gtfs 4.13.2 → 4.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3313,11 +3313,17 @@ function formatHexColor(color) {
3313
3313
  return `#${color}`;
3314
3314
  }
3315
3315
  function formatProperties(properties) {
3316
- const formattedProperties = {
3317
- ...cloneDeep(omitBy(properties, (value) => value === null)),
3318
- route_color: formatHexColor(properties.route_color),
3319
- route_text_color: formatHexColor(properties.route_text_color)
3320
- };
3316
+ const formattedProperties = cloneDeep(
3317
+ omitBy(properties, (value) => value === null || value === void 0)
3318
+ );
3319
+ const formattedRouteColor = formatHexColor(properties.route_color);
3320
+ const formattedRouteTextColor = formatHexColor(properties.route_text_color);
3321
+ if (formattedRouteColor) {
3322
+ formattedProperties.route_color = formattedRouteColor;
3323
+ }
3324
+ if (formattedRouteTextColor) {
3325
+ formattedProperties.route_text_color = formattedRouteTextColor;
3326
+ }
3321
3327
  if (properties.routes) {
3322
3328
  formattedProperties.routes = properties.routes.map(
3323
3329
  (route) => formatProperties(route)
@@ -3325,22 +3331,20 @@ function formatProperties(properties) {
3325
3331
  }
3326
3332
  return formattedProperties;
3327
3333
  }
3328
- function shapesToGeoJSONFeatures(shapes, properties = {}) {
3334
+ function shapesToGeoJSONFeature(shapes, properties = {}) {
3329
3335
  const shapeGroups = Object.values(groupBy(shapes, "shape_id")).map(
3330
3336
  (shapeGroup) => sortBy(shapeGroup, "shape_pt_sequence")
3331
3337
  );
3332
3338
  const lineStrings = consolidateShapes(shapeGroups);
3333
- return lineStrings.map(
3334
- (lineString) => feature(
3335
- {
3336
- type: "LineString",
3337
- coordinates: lineString
3338
- },
3339
- formatProperties(properties)
3340
- )
3339
+ return feature(
3340
+ {
3341
+ type: "MultiLineString",
3342
+ coordinates: lineStrings
3343
+ },
3344
+ formatProperties(properties)
3341
3345
  );
3342
3346
  }
3343
- function stopsToGeoJSON(stops) {
3347
+ function stopsToGeoJSONFeatureCollection(stops) {
3344
3348
  const features = stops.map(
3345
3349
  (stop) => feature(
3346
3350
  {
@@ -4601,7 +4605,7 @@ function getRoutes(query = {}, fields = [], orderBy2 = [], options = {}) {
4601
4605
  }
4602
4606
 
4603
4607
  // src/lib/gtfs/shapes.ts
4604
- import { omit as omit4, pick as pick2 } from "lodash-es";
4608
+ import { compact as compact2, omit as omit4, pick as pick2 } from "lodash-es";
4605
4609
  import sqlString28 from "sqlstring-sqlite";
4606
4610
  import { featureCollection as featureCollection2 } from "@turf/helpers";
4607
4611
 
@@ -4653,35 +4657,39 @@ function getShapesAsGeoJSON(query = {}, options = {}) {
4653
4657
  const agencies = getAgencies2({}, [], [], options);
4654
4658
  const routeQuery = pick2(query, ["route_id"]);
4655
4659
  const routes = getRoutes(routeQuery, [], [], options);
4656
- const features = [];
4657
- for (const route of routes) {
4658
- const shapeQuery = {
4659
- route_id: route.route_id,
4660
- ...omit4(query, "route_id")
4661
- };
4662
- const shapes = getShapes(
4663
- shapeQuery,
4664
- ["shape_id", "shape_pt_sequence", "shape_pt_lon", "shape_pt_lat"],
4665
- [],
4666
- options
4667
- );
4668
- const routeAttributes = getRouteAttributes(
4669
- { route_id: route.route_id },
4670
- [],
4671
- [],
4672
- options
4673
- );
4674
- const agency = agencies.find(
4675
- (agency2) => agency2.agency_id === route.agency_id
4676
- );
4677
- const geojsonProperties = {
4678
- agency_name: agency ? agency.agency_name : void 0,
4679
- shape_id: query.shape_id,
4680
- ...route,
4681
- ...routeAttributes?.[0] || []
4682
- };
4683
- features.push(...shapesToGeoJSONFeatures(shapes, geojsonProperties));
4684
- }
4660
+ const features = compact2(
4661
+ routes.map((route) => {
4662
+ const shapeQuery = {
4663
+ route_id: route.route_id,
4664
+ ...omit4(query, "route_id")
4665
+ };
4666
+ const shapes = getShapes(
4667
+ shapeQuery,
4668
+ ["shape_id", "shape_pt_sequence", "shape_pt_lon", "shape_pt_lat"],
4669
+ [],
4670
+ options
4671
+ );
4672
+ if (shapes.length === 0) {
4673
+ return;
4674
+ }
4675
+ const routeAttributes = getRouteAttributes(
4676
+ { route_id: route.route_id },
4677
+ [],
4678
+ [],
4679
+ options
4680
+ );
4681
+ const agency = agencies.find(
4682
+ (agency2) => agency2.agency_id === route.agency_id
4683
+ );
4684
+ const geojsonProperties = {
4685
+ agency_name: agency ? agency.agency_name : void 0,
4686
+ shape_id: query.shape_id,
4687
+ ...route,
4688
+ ...routeAttributes?.[0] || []
4689
+ };
4690
+ return shapesToGeoJSONFeature(shapes, geojsonProperties);
4691
+ })
4692
+ );
4685
4693
  return featureCollection2(features);
4686
4694
  }
4687
4695
 
@@ -4790,7 +4798,7 @@ function getStopsAsGeoJSON(query = {}, options = {}) {
4790
4798
  };
4791
4799
  });
4792
4800
  const filteredStops = preparedStops.filter((stop) => stop.routes.length > 0);
4793
- return stopsToGeoJSON(filteredStops);
4801
+ return stopsToGeoJSONFeatureCollection(filteredStops);
4794
4802
  }
4795
4803
 
4796
4804
  // src/lib/gtfs/stop-times.ts