Home arrow GIS Data & Resources arrow Scripts and Code
GIS-Related Scripts and Programming Code

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).

Category Links:

GIS Scripts and Code (Weblog format, All Posts):




ArcMap .CAL Script: Spatial Join-Based Geometry Transfer PDF Print E-mail

Written by Bert Granberg,

Updated 11/5/09

You have a layer of polygons, say grazing permits, that are mostly based on another layer, say state and federal land ownership. Let's say the base data layer, land ownership, gets updated due to an improved survey. Is there an easy way to make the geometry adjustment to the grazing permits.

There are a couple of options to explore within the ArcMap UI, namely:

  • Spatial Joins.Good approach but creates a new dataset as a result and sometimes the dataset + dataset = new dataset approach doesn't meet requirements and/or makes an unnecessary mess
  • Spatial Adjustment toolbar --> Attribute Transfer tool, Geometry Transfer option. Also a good approach but involves mouse clicks, is not customizable, and doesn't resolve matching between single and multipart features

Here is another option, a .CAL script to run in the ArcMap field calculator on a selected set, within an edit session.

Before and after polygon geometry transfer adjustment

TO USE: 

  1. open the attribute table for the target feature class (grazing in the example above), select one or more features (start with one at a time).
  2. Right click on the SHAPE field or hit CTRL + SHIFT + F to open the field calculator.
  3. In the field calculator, check the Advanced Option box and paste the script below in the Pre-Logic VBS Script Code text box.
  4. Make sure that the source layer number script parameter is set, This can be found by searching for SET THIS in the code. Set the layer index number for the polygon layer with the source geometry
  5. In the bottom box, under Shape =, type in: pOutPolygon

Notes:

If you're running this on a big selected set, the message box (shown below) will bug you. It can easily be disabled or deleted if desired. It's at the end of the script and can be disabled by sticking an apostrophe (') in front of it to comment that function out.

Quick report that will pop up for every feature, unless disabled

 

Comment on this Article
04, Nov. 2009
Last Updated ( 05, Nov. 2009 )
Read more...
 
VBA: Generate Elevation Profiles for PolylineM Routes PDF Print E-mail

Written by Bert Granberg,

Calibrated polylineM route features carry a milepost-measure value in addition to the standard x,y coordinate pair.

Having the milepost coordinate makes is convenient for generating the data necessary to make an elevation profile for each route because you can use the m coordinate to make sure all the elevation measures are about the same distance apart.

Utah Highway 12 Elevation Profile

For the profiles that I generated for Utah highways [access all elevation profiles here], I used the endpoint calibrated routes) together with an SDE-based 10 meter statewide DEM:

  • SGID93.TRANSPORTATION.UDOTRoutes_CalibratedEP
  • SGID93.RASTER.DEM_10METER

I wanted to do this without having a 3D Analyst license and in an automated manner (i.e. no mouse driving through the ArcMap UI).

The first step was to create a .csv table of the elevation from the DEM at every 1/10th of a mile along the route using a VBS script (below) called: elevationValuesAlongRoutesToCSV

Next I loaded the .csv table into ArcMap and ran a script to automate the creation of the elevation profile graph from the .csv table. For this there are two scripts (below) that offer the choice of a line-based graph or a scatterplot graph.

Although the new graphing functionality (available since the 9.2 release, I think) is very powerful, it's a bit hard to use and  never figured out how to control the line graph where 'no data' areas are present in routes with separated parts (like where I-84 runs concurrent with I-15 for a few miles). Graphs can be created with this code for future use within the ArcMap UI or they can be automatically exported to a variety of formats (.png, .pdf, etc.).

Notes:

  • The text in the example above was added manually
  • Graphs in the linegraphs folder (from the link above) have scaled elevation (you can't judge slope without factoring in the y axis)
  • Graphs in the scatterplotsgraphs folder have a non-scaled (constant) elevation representation on the Y axis that is consistent from one graph to the next.
Comment on this Article
03, Nov. 2009
Last Updated ( 04, Nov. 2009 )
Read more...
 
ArcGIS Server - Pseudo Concurrent editing strategy PDF Print E-mail

Written by Steve Gourley,

When building geospatial editing web applications one needs to plan, or don't, for the fact that two people may edit SDE data at the same time. If you aren't and your application isn't used frequently then it is probably not an issue, yet. But you may start to see this error and not know what to do.

The version has been redefined to reference a new database state. [sde.DEFAULT] What happens is more than one edit session starts and one finishes before the rest. This redefines the SDE states table which causes the subsequent save edit operations to fail.  

Our strategy was to put the editing operation in a do while loop. Basically, do the edit operation while SDE did not kick out a version mismatch error. In the code we check if the version has been redefined, if it has refresh it and try again.

A possible better approach would be to create a unique version per edit operation and reconcile that version or lock the thread that has started the edit operation and queue subsequent requests until the lock has been removed.

What are your strategies for overcoming database concurrency?

 

Comment on this Article
23, Sep. 2009
Last Updated ( 23, Sep. 2009 )
Read more...
 
VBA: Generate Milepost Locations From PolylineM Routes PDF Print E-mail

Written by Bert Granberg,

This VBA script is designed to derive the location for mileposts routes in a polylineM feature class that has already been created.

In addition to an x and y coordinate, a polylineM routes contain a measure (m) coordinate with the milepost coordinate for every vertex. In some cases, information exists to calibrate the route at endpoints but the locations for mileposts are unknown.

The code works for single and multipart route features. It interates through the routes and writes a record to an output .csv file for each milepost expected along the parts that make up a route. If a route starts at 0 goes to 3.777 then records will be created for 0,1,2 abd 3 mileposts. X and Y coordinates are also written for each route-milepost record.

The next step is easy. Add the resulting .csv file to ArcMap, right click on it and select the 'Display XY Data' context menu item.

A set of milepost approximate locations has been created for Utah and they are now loaded into an SGID layer named SGID93.TRANSPORTATION.UDOTMilepost_Approx.

 

Comment on this Article
17, Sep. 2009
Last Updated ( 21, Sep. 2009 )
Read more...
 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 1 - 8 of 130

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for