BlinkTagInc / gtfs-to-geojson

Generate geoJSON of transit route data from a GTFS file.
MIT License
114 stars 23 forks source link

Invalid Json generated? #26

Closed eMerzh closed 2 months ago

eMerzh commented 2 months ago

Hello again, everything seems fine but i look at some of my files, and they seems to be invalid JSON....

the command was launched with

{
    "agencies": [
        {
            "agency_key": "tec",
            "path": "/Users/xxx/Downloads/TEC-GTFS/"
        }
    ],
    "bufferSizeMeters": 400,
    "coordinatePrecision": 5,
    "outputType": "route",
    "outputFormat": "lines-and-stops",
    "startDate": "20240616",
    "endDate": "20240617",
    "verbose": true,
    "zipOutput": false
}

here is an example (renamed as json for gh) N_69_1.json

brendannee commented 2 months ago

Thanks for pointing this out. It looks like this GTFS has multiple entries in routes.txt for the same agency_id/route_short_name/direction_id which is what gtfs-to-geojson was using to generate output filenames. This caused N_69_1.json to be written to more than once which is why the JSON is invalid.

I pushed an update that checks if the file exists, and if it does appends the route_id (which should be unique) so that files don't get overwritten. This should be a fairly rare occurrence - I think most GTFS has route_short_name unique.

So with this GTFS, you'll end up with files like:

N_69_1_N2690-19479.geojson N_69_1_X9690-19304.geojson

Check out the latest version and let me know what you think: https://github.com/BlinkTagInc/gtfs-to-geojson/releases/tag/3.7.1

eMerzh commented 2 months ago

Hello :) Thanks for the quick action again 🎉

I think it fixed a few of them but I still got like 11 or so that are broken 😓

like this one : H_16_0.json

Side note, I like the routeid trick:) in fact i like to have a predicable name in the file, and it starts to be increasingly hard with the maybe concat / sanitze of all the fields direction, shortname, route,... is there a way to have that predicable? like by routeid or something ?

brendannee commented 2 months ago

Good point on wanting predictable file names.

I released an updated version that uses route_id instead of route_short_name to work around this. https://github.com/BlinkTagInc/gtfs-to-geojson/releases/tag/3.7.2

In the event that there are multiple lines in routes.txt with the same route_id and agency_id, it will append a number to the end of the filename to attempt to keep them unique. But this scenario shoud be rare and probably means there is a problem with the GTFS.

Try it out and let me know what you think.

eMerzh commented 2 months ago

AAAaaand fixed for me 🎉

Again, many thx for your quick response :)