Script for snapping feature classes in 2 different feature datasets

694
4
Jump to solution
08-08-2013 01:55 AM
ConorMoloney
New Contributor III
I have 2 Feature Datasets in a geodatabase. One dataset contains bus routes and the other contains bus stops for each route. I want to create a script that will snap the bus stops to the vertex of the relevant bus route. There are over 100 routes and stops. They are stored in each dataset in order. They are named like this S102, S104 etc. for stops and B102, B104 for routes. I'm unsure about how to do a for loop that will get a stop and then get the right bus route
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Sorry for not being clear. The routes B102, B104 etc. are polylines and the stops S102, S104 etc. are points. The reason they have to be snapped to a vertex is that they are going to be used in a network dataset where the stops need to be at a vertex for the purpose of transfers. I tried using a model builder but only being able to use one iterator meant I couldn't do it. I tried putting one iterator in a sub-model and running it but I was not able to do it correctly. The submodel would iterate through all of the feature classes and then output the last feature class in the dataset, this would then be used in the main model. This repeated itself for each iteration of the main model.

Main Model
[ATTACH=CONFIG]26583[/ATTACH]

Sub Model
[ATTACH=CONFIG]26584[/ATTACH]


Are you sure you used a variable and not a hard coded value for the output of the Snap?  For example, base the output name of each feature class on the %Name% variable, not something line "Stop_Snap".  So for example the output of each iteration would look like:  Path/%Name%_Stop_Snap

You are giving up too early on Iterators.  Python would be a much harder thing to tackle than figuring out where you are going wrong with an Iterator.

Also, I personally find looking at the model connections is meaningless for troubleshooting a model, especially one involving an Iterator.  Screen shot the actual tool dialogs for each step of the model to find the problem and get the best help.  Where did you use variables in those dialogs?  If you didn't use variables, that is where you went wrong.

View solution in original post

0 Kudos
4 Replies
RichardFairhurst
MVP Honored Contributor
I have 2 Feature Datasets in a geodatabase. One dataset contains bus routes and the other contains bus stops for each route. I want to create a script that will snap the bus stops to the vertex of the relevant bus route. There are over 100 routes and stops. They are stored in each dataset in order. They are named like this S102, S104 etc. for stops and B102, B104 for routes. I'm unsure about how to do a for loop that will get a stop and then get the right bus route


Do the B102 and B104 exist as points or just vertices without attributes that name them the way you have described and you want to create them?

If the B102 positions already exist as points connected to the route, why not extract just the numeric part of the Stop and Bus into their own field so that those numbers can act as a join field?  That way you can pass the coordinates of the Bus Routes to the Stops with a Join and the Field Calculator.  Then export the stops data as a Standalone Table.  Then use the Make X/Y Event Layer to create a new Stops point layer that will match all of the Bus routes.  Use Feature Class to Feature Class to permanently store that layer as a real Point Feature class.  A 10 minute task with no scripting required.  You can do it all in Model Builder (and export it to a Python Script if you need it to run as a script multiple times).

Anyway the picture you have described is not adequate to understand what you are dealing with.  It may seem clear to you, since you can see your data, but it is totally unclear what feature types you are dealing with and why you need to snap only to vertices and not just nearest point on the line, etc.  What is the tolerance of the snapping?  In other words, why look for a script solution at all and not a more straight forward geoprocessing solution?
0 Kudos
ConorMoloney
New Contributor III
Sorry for not being clear. The routes B102, B104 etc. are polylines and the stops S102, S104 etc. are points. The reason they have to be snapped to a vertex is that they are going to be used in a network dataset where the stops need to be at a vertex for the purpose of transfers. I tried using a model builder but only being able to use one iterator meant I couldn't do it. I tried putting one iterator in a sub-model and running it but I was not able to do it correctly. The submodel would iterate through all of the feature classes and then output the last feature class in the dataset, this would then be used in the main model. This repeated itself for each iteration of the main model.

Main Model
[ATTACH=CONFIG]26583[/ATTACH]

Sub Model
[ATTACH=CONFIG]26584[/ATTACH]
0 Kudos
RichardFairhurst
MVP Honored Contributor
Sorry for not being clear. The routes B102, B104 etc. are polylines and the stops S102, S104 etc. are points. The reason they have to be snapped to a vertex is that they are going to be used in a network dataset where the stops need to be at a vertex for the purpose of transfers. I tried using a model builder but only being able to use one iterator meant I couldn't do it. I tried putting one iterator in a sub-model and running it but I was not able to do it correctly. The submodel would iterate through all of the feature classes and then output the last feature class in the dataset, this would then be used in the main model. This repeated itself for each iteration of the main model.

Main Model
[ATTACH=CONFIG]26583[/ATTACH]

Sub Model
[ATTACH=CONFIG]26584[/ATTACH]


Are you sure you used a variable and not a hard coded value for the output of the Snap?  For example, base the output name of each feature class on the %Name% variable, not something line "Stop_Snap".  So for example the output of each iteration would look like:  Path/%Name%_Stop_Snap

You are giving up too early on Iterators.  Python would be a much harder thing to tackle than figuring out where you are going wrong with an Iterator.

Also, I personally find looking at the model connections is meaningless for troubleshooting a model, especially one involving an Iterator.  Screen shot the actual tool dialogs for each step of the model to find the problem and get the best help.  Where did you use variables in those dialogs?  If you didn't use variables, that is where you went wrong.
0 Kudos
ConorMoloney
New Contributor III
I didn't know about the variables. Thank you very much, that solved my problem.
0 Kudos