Relation between GTFS shapes and GTFS LineVariant

1414
6
Jump to solution
07-19-2022 07:52 AM
NATHANMARYCAMPION
New Contributor II

Hello,

After I loaded my GTFS data on ArcGisPro, i've deployed my GTFS's shapes with this tool:https://pro.arcgis.com/fr/pro-app/latest/tool-reference/public-transit/gtfs-shapes-to-features.htm

This one deploy my shapes directly from my GTFS datas (shapes.txt file).

 

Here is the table of the layer when deployed:

NATHANMARYCAMPION_1-1658236682080.png

(The right of table is just infos like the line's color...)

Here, one shape is equal to one route.

As you can see, all my routes are identified by line (route_id, route_short_name...) and by shape with the primary key "shape_id".

This "shape_id" doesn't match with my table LineVariant who identify the routes in the data model.

 

For example:

Here my LineVariant table:

NATHANMARYCAMPION_0-1658241080336.png

Each routes is here define by the ID column. The Line_id identify a group of ID (a group of routes so).

The ID of LineVariant don't match with the shape_id: if i choose the LineVariant ID "10" , it will not match with the shape_id n°10

 

So two questions:

- Is it possible to make a relation class between those two tables?

- If not, how can I include the shape layer into my database?

It seem odd for datas coming from same files and deployed by  same software that they can't communicate.

Sorry for my bad english, I hope i'm clear.

0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

Okay, this was a fun little challenge.  I created a script and Python Toolbox that will add a GShapeID field to the LineVariants table populated with the GTFS shape_id (attached).  You should be able to run the tool or use the script directly in a Python workflow.  I think it should be pretty straightforward, but let me know if you have any questions.

The script matches up stop sequences in the GTFS stop_times.txt file and the LineVariantElements feature class from the Public Transit Data Model and uses the relationships between the various tables to figure out the shape_id associated with each LineVarID.  If for some reason it can't find a matching stop sequence, it just leaves the GShapeID field blank (I've seen this in cases where a LineVariantElement was deleted because it had null geometry - something the GTFS To Public Transit Data Model tool does automatically to avoid network dataset build errors.)

The script currently does not have any data validation and relies on good input data.

Please let me know if this works for you.

I will consider enhancing the GTFS To Public Transit Data Model tool to populate the GShapeID field automatically in a future release of ArcGIS Pro.  I'll leave a comment here if that happens.

View solution in original post

6 Replies
MelindaMorang
Esri Regular Contributor

Hello.

I think what you're asking is how you can make the geometry of the LineVariantElements look like your shapes.txt file so that the transit lines appear to follow their actual geographic paths instead of simple straight-line connections between stops.  Is that correct?

If so, there is no need to do this.  The Public Transit evaluator in the network dataset does not care about the geometry of the LineVariantElements.  It looks up the travel times in the various Public Transit Data Model tables.

There are several reasons we don't use the geometry from shapes.txt for the network dataset:

  1. The shapes.txt file is optional, so we can't rely on it being there.
  2. Often the shapes derived from a shapes.txt file are messy or inaccurate (or missing).
  3. Good connectivity with stops is essential in a network dataset, and the data from shapes.txt does not have a straightforward relationship with stops.

You should not try to use your network dataset and its LineVariantElements feature class for visualization.  It is designed specifically for analysis. But, I would be interested to understand your goal - what are you actually trying to do?

To answer your specific questions:

From your screenshot of the output of GTFS Shapes To Features, it looks like most routes have multiple shapes.  For instance, route_id A_562 has four shape_ids: 10, 11, 12, 9.

The GTFS shape_id is not used in the LineVariants table.  One reason is that shape_id can be a string, and we chose to use numeric values as IDs for our Public Transit Data Model.  Also, although we provide tools to convert from GTFS to the Public Transit Data Model, you could instead use some non-GTFS source of transit data.  Also, as I said before, the shapes.txt file is optional.  So, you should not consider the ID field in LineVariants equivalent to the shape_id field in shapes.txt, but you are correct that LineVariants are conceptually equivalent to shapes.  But...yeah, there is no good way to join the LineVariants table to the output of GTFS Shapes To Features.

If you tell me more about what you're trying to do, I might be able to give more useful advice.

0 Kudos
NATHANMARYCAMPION
New Contributor II

Thanks for your response

I make a small app of a public transport system based on informations given by a company. They work with the GTFS format but I can't use it raw because:

- It is not adapted to my app (I use the webappbuilder), the datas are more complicated to find and understand in the GTFS data model. Also, some datas are useless.

- It can be complicated to update and change things for laymans (I'm just here for few months and no one know about GIS in the structure)

So I work on a data model more compact build with datas extracted from the GTFS.

I need the shapes of my routes linked to the rest of my data model for UX and cartographical purposes, the user should be able to click on a route and have all datas linked (like the number of passengers for exemple) or just display linked layers (like the stops of a route).

 

So my goal is not to transform LineVariantElements into a geographic path of my grid, but to find a way to import the shapefile given by GTFS shape to feature into my database. The shape.txt file contain datas of pretty good quality and use other datas produced in other way leads to a loss of details.

But you think their is no way to link properly  my routes shape to my LineVariant?

0 Kudos
MelindaMorang
Esri Regular Contributor

So you are developing a web app to show information about the public transit system, but you are not trying to create a passenger-facing routing, app, correct?  Interesting.  This is not a use case I'd anticipated for the Public Transit Data Model.

I might be able to find a way to link the output of GTFS Shapes To Features to the data model, but I'll have to think about it and do some experiments.

MelindaMorang
Esri Regular Contributor

Okay, this was a fun little challenge.  I created a script and Python Toolbox that will add a GShapeID field to the LineVariants table populated with the GTFS shape_id (attached).  You should be able to run the tool or use the script directly in a Python workflow.  I think it should be pretty straightforward, but let me know if you have any questions.

The script matches up stop sequences in the GTFS stop_times.txt file and the LineVariantElements feature class from the Public Transit Data Model and uses the relationships between the various tables to figure out the shape_id associated with each LineVarID.  If for some reason it can't find a matching stop sequence, it just leaves the GShapeID field blank (I've seen this in cases where a LineVariantElement was deleted because it had null geometry - something the GTFS To Public Transit Data Model tool does automatically to avoid network dataset build errors.)

The script currently does not have any data validation and relies on good input data.

Please let me know if this works for you.

I will consider enhancing the GTFS To Public Transit Data Model tool to populate the GShapeID field automatically in a future release of ArcGIS Pro.  I'll leave a comment here if that happens.

NATHANMARYCAMPION
New Contributor II

It works fine! Thank you for your help!

0 Kudos
MelindaMorang
Esri Regular Contributor

The GTFS To Public Transit Data Model tool should populate the GShapeID field in LineVariants automatically starting in ArcGIS Pro 3.1.