This section provides a venue for sharing GIS-related programming code and custom scripts in a variety of languages. Posts can be viewed by category or as a whole in blog format (below).
This ArcMap Field Calculator script will update the SHAPE geometry field in an ArcGIS polylineM feature class to reflect new m coordinate values from a given set of calibration points (usually milepost locations). Use within an edit session and checking the result with the Sketch Properties tool is highly recommended.
TO USE:
open the attribute table for the route feature class, select an individual route.
Right click on the SHAPE field or hit CTRL + SHIFT + F to open the field calculator.
In the field calculator, check the Advanced Option and paste the script below in the Pre-Logic VBS Script Code text box.
Make sure that the 3 script parameters are set, These can be found by searching for SET THESE in the code
layer index number for the calibration point feature class
name of the field containing the calibration values
query string to restrict the calibration point set to just the given route
Type the word pMSegmentation2 into the field calculator's bottom text box and hit OK
Bookmarks allow you to quickly navigate to pre-defined geographic extent rectangles and can be extremely useful for data quality assessment when your data is located across a large area.
This script was developed to create an Area of Interest (AOI) bookmark that can be accessed from the View menu in ArcMap. It was written specifically to create a bookmark for each state highway, each highway's multiple parts (where the route is broken into discontiguous parts), and each part's start and end point
I used this against the SGID93.Transportation.UDOTRoutes_Calibrated_EP route layer but you could modify this to work with just about anything. To run, make sure the layer you want to generate the bookmarks from is at the top of the ArcMap Table of Contents (TOC). Paste the code and make modifications (sort field, buffer size for end points, the way the AOI name is generated, etc). Most of the length of this script is from handling multipart features differently...it could be greatly simplified as needed.
Bookmarks will be added so they can be viewed from both the Bookmark manager and the View-->Bookmarks menu item. Here are the results (at right).
Bookmark files can also be saved and loaded as .dat files through the ArcMap bookmark manager.
Wouldn't it be nice if you could take one of you python data objects and just "can it" to open up later? With the "pickle" library you can do just that.
I need to compare current data to historical data, so I make a dictionary of OID's with all attributes that looks something like this:
PK99999: (1059, 4, X, Y, etc, etc...) PK00001: (1259, 2, X, Y, etc, etc...)
So, I like to slurp this dictionary up into a pickle, then open it up a month later to compare against the current data.
This code automates the building and calibration of polyline-m route features from street centerlines that carry a route and route-part identifier. In addition to an attributed street centerline input dataset, a feature class of calibration points is required with one calibration point per route part.
Before starting, each route's component centerline features must be coded into separate parts wherever the route is disjoint or broken and wherever spurs and loops occur.
For example, I-80 in Utah consists of two parts, one west of I-15 and one east of I-15. There is a gap of about 3 miles between these parts and the mileposting stops and resumes one either side of this gap. All of the centerlines west of I-15 in the positive direction should carry a RT_NAME = 0080P and a RT_PART = 1, Everything east of I-15 in the positive direction should carry RT_NAME = 0080P and a RT_PART =2. There need to be four calibration points one for each start and end point on each of the 2 route parts.
Looping is always a little problematic and my favored way to represent loops is to put a very small part at the end of the loop (where the feature comes back together) and set its calibration measures to -9999. This breaks the loop into two parts so that none of the start and end points are coincident for a single part. After the route is calibrated this little part can be deleted and you can can reclose the loop.
Route building can of course be done in model builder and the ArcGIS command line editor as well. However, I prefer using this code for large batch route building jobs. It is fast relative to the GP environment of the alternatives.
Important notes:
This code will attempt to build all the routes for which you have calibration points. If you want to build just a select set of routes, set a definition query (temporary subset) in your calibration layer's properties.
The route output feature class will carry a date/time stamp in the feature class name.
Where route have multiple parts (like I-80 described above), you'll want to run the improvedRoutePartMerge procedure (included in the code below) to merge the calibrated route parts together into a single route feature. This procedure, unlike the built in Merge tool in ArcMap, will always produce a merged route that maintains the original component part geometry and the component part ordering. Running the script creates the merged routes and adds them to the pre-merged route feature class. Open an edit session and delete the pre-merged features and you're done.
Occasionally routes directional orientation will be the reverse of the measure coordinates. This is not a problem within ArcMap unless you want to draw arrowhead symbols on the route features, but this can cause violate some other systems integrity rules. In this case, routes can be flipped within an ArcMap edit session (right click on edit sketch and choose 'Flip.' M coordinates will stay where they are supposed to be.
Possible errors include missing or incorrectly coded part endpoints, branching of route without it being broken into parts (with endpoints for each part), duplicate or overlapping street features coded as part of the route, street features composed of geometric curves (use ianko.com's easycalculate 'shape_densify' field calculator function to get rid of them).
The code consists of one procedure, BuildRoutesParts_SimpleCalibration(), and 5 related functions. Make sure to investigate and set the parameters required in the BuildRoutesParts_SimpleCalibration procedure.