gtfs 4.13.1 → 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
@@ -255,7 +255,7 @@ var model5 = {
255
255
  },
256
256
  {
257
257
  name: "date",
258
- type: "integer",
258
+ type: "date",
259
259
  required: true,
260
260
  primary: true
261
261
  },
@@ -339,13 +339,13 @@ var model6 = {
339
339
  },
340
340
  {
341
341
  name: "start_date",
342
- type: "integer",
342
+ type: "date",
343
343
  required: true,
344
344
  index: true
345
345
  },
346
346
  {
347
347
  name: "end_date",
348
- type: "integer",
348
+ type: "date",
349
349
  required: true,
350
350
  index: true
351
351
  }
@@ -641,11 +641,11 @@ var model13 = {
641
641
  },
642
642
  {
643
643
  name: "feed_start_date",
644
- type: "integer"
644
+ type: "date"
645
645
  },
646
646
  {
647
647
  name: "feed_end_date",
648
- type: "integer"
648
+ type: "date"
649
649
  },
650
650
  {
651
651
  name: "feed_version",
@@ -1498,11 +1498,11 @@ var model31 = {
1498
1498
  },
1499
1499
  {
1500
1500
  name: "start_date",
1501
- type: "integer"
1501
+ type: "date"
1502
1502
  },
1503
1503
  {
1504
1504
  name: "end_date",
1505
- type: "integer"
1505
+ type: "date"
1506
1506
  },
1507
1507
  {
1508
1508
  name: "monday",
@@ -2007,7 +2007,7 @@ var model41 = {
2007
2007
  },
2008
2008
  {
2009
2009
  name: "service_date",
2010
- type: "integer",
2010
+ type: "date",
2011
2011
  index: true
2012
2012
  },
2013
2013
  {
@@ -2089,7 +2089,7 @@ var model42 = {
2089
2089
  },
2090
2090
  {
2091
2091
  name: "service_date",
2092
- type: "integer",
2092
+ type: "date",
2093
2093
  index: true
2094
2094
  },
2095
2095
  {
@@ -2173,12 +2173,12 @@ var model43 = {
2173
2173
  },
2174
2174
  {
2175
2175
  name: "ridership_start_date",
2176
- type: "integer",
2176
+ type: "date",
2177
2177
  index: true
2178
2178
  },
2179
2179
  {
2180
2180
  name: "ridership_end_date",
2181
- type: "integer",
2181
+ type: "date",
2182
2182
  index: true
2183
2183
  },
2184
2184
  {
@@ -2301,7 +2301,7 @@ var model44 = {
2301
2301
  },
2302
2302
  {
2303
2303
  name: "service_date",
2304
- type: "integer",
2304
+ type: "date",
2305
2305
  index: true
2306
2306
  },
2307
2307
  {
@@ -2348,17 +2348,17 @@ var model45 = {
2348
2348
  },
2349
2349
  {
2350
2350
  name: "ride_start_date",
2351
- type: "integer",
2351
+ type: "date",
2352
2352
  index: true
2353
2353
  },
2354
2354
  {
2355
2355
  name: "ride_end_date",
2356
- type: "integer",
2356
+ type: "date",
2357
2357
  index: true
2358
2358
  },
2359
2359
  {
2360
2360
  name: "gtfs_feed_date",
2361
- type: "integer",
2361
+ type: "date",
2362
2362
  index: true
2363
2363
  },
2364
2364
  {
@@ -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
  {
@@ -3825,7 +3829,17 @@ var formatLine = (line, model56, totalLineCount) => {
3825
3829
  const formattedLine = {};
3826
3830
  for (const columnSchema of model56.schema) {
3827
3831
  const lineValue = line[columnSchema.name];
3828
- if (columnSchema.type === "integer") {
3832
+ if (columnSchema.type === "date") {
3833
+ if (lineValue !== "" && lineValue !== void 0) {
3834
+ const dateValue = lineValue.replace(/-/g, "");
3835
+ if (dateValue.length !== 8) {
3836
+ throw new Error(
3837
+ `Invalid date in ${model56.filenameBase}.${model56.filenameExtension} for ${columnSchema.name} on line ${lineNumber}.`
3838
+ );
3839
+ }
3840
+ formattedLine[columnSchema.name] = Number.parseInt(dateValue, 10);
3841
+ }
3842
+ } else if (columnSchema.type === "integer") {
3829
3843
  formattedLine[columnSchema.name] = Number.parseInt(lineValue, 10);
3830
3844
  } else if (columnSchema.type === "real") {
3831
3845
  formattedLine[columnSchema.name] = Number.parseFloat(lineValue);
@@ -4591,7 +4605,7 @@ function getRoutes(query = {}, fields = [], orderBy2 = [], options = {}) {
4591
4605
  }
4592
4606
 
4593
4607
  // src/lib/gtfs/shapes.ts
4594
- import { omit as omit4, pick as pick2 } from "lodash-es";
4608
+ import { compact as compact2, omit as omit4, pick as pick2 } from "lodash-es";
4595
4609
  import sqlString28 from "sqlstring-sqlite";
4596
4610
  import { featureCollection as featureCollection2 } from "@turf/helpers";
4597
4611
 
@@ -4643,35 +4657,39 @@ function getShapesAsGeoJSON(query = {}, options = {}) {
4643
4657
  const agencies = getAgencies2({}, [], [], options);
4644
4658
  const routeQuery = pick2(query, ["route_id"]);
4645
4659
  const routes = getRoutes(routeQuery, [], [], options);
4646
- const features = [];
4647
- for (const route of routes) {
4648
- const shapeQuery = {
4649
- route_id: route.route_id,
4650
- ...omit4(query, "route_id")
4651
- };
4652
- const shapes = getShapes(
4653
- shapeQuery,
4654
- ["shape_id", "shape_pt_sequence", "shape_pt_lon", "shape_pt_lat"],
4655
- [],
4656
- options
4657
- );
4658
- const routeAttributes = getRouteAttributes(
4659
- { route_id: route.route_id },
4660
- [],
4661
- [],
4662
- options
4663
- );
4664
- const agency = agencies.find(
4665
- (agency2) => agency2.agency_id === route.agency_id
4666
- );
4667
- const geojsonProperties = {
4668
- agency_name: agency ? agency.agency_name : void 0,
4669
- shape_id: query.shape_id,
4670
- ...route,
4671
- ...routeAttributes?.[0] || []
4672
- };
4673
- features.push(...shapesToGeoJSONFeatures(shapes, geojsonProperties));
4674
- }
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
+ );
4675
4693
  return featureCollection2(features);
4676
4694
  }
4677
4695
 
@@ -4780,7 +4798,7 @@ function getStopsAsGeoJSON(query = {}, options = {}) {
4780
4798
  };
4781
4799
  });
4782
4800
  const filteredStops = preparedStops.filter((stop) => stop.routes.length > 0);
4783
- return stopsToGeoJSON(filteredStops);
4801
+ return stopsToGeoJSONFeatureCollection(filteredStops);
4784
4802
  }
4785
4803
 
4786
4804
  // src/lib/gtfs/stop-times.ts