News

ArcUser Online


Search ArcUser

-

E-mail to a Friend

Road Repairs
Splitting polylines with visual basic scripting
By Mike Price, Entrada/San Juan, Inc.

This article as a PDF .

 

What You Will Need

  • ArcGIS Desktop (ArcView, ArcEditor, or ArcInfo license)
  • Sample data (splittinglines.zip)

Before working this exercise, you should complete "Under Construction: Building and Calculating Turn Radii" so you will understand how to calculate turn radii.

"Under Construction: Building and Calculating Turn Radii" showed how to calculate turns or curve radii for a steep, winding road. The tutorial used predefined tangent points to create turn chords and to split a road centerline. This exercise will reinforce the turn chord construction technique taught in that article and teach endpoint modeling. It uses a Visual Basic (VB) script that splits all constructed curves in just one run.

This tutorial includes five tasks:

Task 1: After creating turn chords, add fields to store coordinates of start and endpoints.
Task 2: Calculate coordinates of start and endpoints.
Task 3: Load all endpoints as event themes.
Task 4: Run the Visual Basic script to the split road centerline at turn chord endpoints.
Task 5: Assign turn numbers and join turn chord and middle ordinate lengths, then calculate turn radii.

click to enlarge
Create four new fields to store X and Y coordinates for both endpoints.

Getting Started

Download the splittinglines.zip training set from ArcUser Online. Extract the data into a project folder and preview it in ArcCatalog. This exercise uses the original road centerline and constructs turn chords and middle ordinates. Hint: When building chords from scratch, be sure to snap to road centerline vertices.

\Chuckanut2\Chuckanut2.mxd. Navigate to \Chuckanut2\SHPFiles\WASP83NFH and add the Turn Chords layer. Open and inspect its table. We will use chord endpoint coordinates to create our splitting points.

Task 1: Add Endpoint Coordinate Fields

First, create four new fields to store X and Y coordinates for both endpoints. These points will be stored in Washington State Plane North American Datum of 1983 (NAD 83) High Accuracy Reference Network (HARN) North in U.S. Feet.

  1. Open the Turn Chords table and review its structure.
  2. Open Options and select Add Field. Name the field Start_X, set its Type to Double, and set its precision to 14 and its scale to 4. Because this point must be on or very near the target line, the extra precision should help.
  3. Add three more fields named Start_Y, End_X, and End_Y. Use the same data type, precision, and scale for all fields.

Task 2: Calculate and Copy Endpoint Coordinates

How to calculate the endpoint coordinates.

  1. Begin by right-clicking on the Start_X field on its table header and select Calculate Geometry. Set Property to X Coordinate of Line Start. Use the data frame's coordinate system and set units to Feet U.S. [ft]. Click OK to calculate coordinates.
  2. Continue to calculate coordinates for Start_Y, End_X, and End_Y using the same procedure. Select the correct property for each field (e.g., End_X for the End_X field), and if the wrong property is selected, just recalculate the field.
  3. Navigate to the select \Chuckanut2\SHPFiles\WASP83NFH and copy Chord1.dbf to the clipboard. Navigate to \Chuckanut2\DBFFiles and paste Chord1.dbf in this folder. Right-click on the file and rename it Chord1_XY.dbf.
  4. Add Chord1_XY.dbf back to the ArcMap document and switch to the table of contents (TOC) Source tab. Save the project.

Task 3: Load Endpoints as Event Themes

  1. In the Source tab, open and inspect Chords1_XY. Right-click on this table in the TOC and choose Display XY Data. Enter X_Start for the XField and Y_Start for the YField to define the Event Theme. Import the coordinate system from Chords1.shp. Rename this layer StartPoints.
  2. Right-click on Chords1_XY again, and again choose Display XY Data. Enter X_End for the XField and Y_End for the Yfield. Import the coordinate system from Chords1.shp. Rename this layer EndPoints.
  3. Carefully inspect the points to verify that they are very close to the actual end-points of each chord. Zoom to Bookmark CR MP 0.0 1:3,000. Save the project.

Task 4: Load and Run the Line Splitting Script

click to enlarge
After making the event themes, StartPoints and EndPoints, the only selectable themes, select all points and run the SplitLinesAtPoints script.

A Visual Basic script that uses points to split line segments will be used to split the Chuckanut Ridge Road centerline. The script and supporting information are available in the \Chuckanut2\Utility\ folder.

  1. It is important to remove Turn Chords from the project so the only polyline theme is Chuckanut Ridge Road.
  2. In the ArcMap standard menu, choose Tools > Macros > select Visual Basic Editor to open an empty VB scripting window.
  3. After the VB Editor opens in its own window, locate the Project window and notice the Normal and Project selections. Selecting Normal will store changes for all maps accessed on this computer. Selecting Project will store changes only for this map document. For this model, select and expand Project.
  4. In the VB Editor standard menu, choose the File > Import File. Navigate to \Chuckanut2\Utility, locate SplitLinesAtPoints.bas, and click Open.
  5. Expand the Modules folder; double-click the SplitLinesAtPoints module to view the VB code. No changes are required to this code. Close VB Window. Save the ArcMap document now to save this script in this project.
  6. To run the script in ArcMap, verify that the polyline target (Chuckanut Ridge Road) and the splitting points (StartPoints and Endpoints) are in the TOC. Zoom to Bookmark CR All 1:12,000.
  7. Choose Tools > Editor toolbar to load the Editor toolbar, and choose Editor > Start Editing from the drop-down menu. Select the \Chuckanut2\SHPFiles\WASP83NFH\ folder as the folder to edit data from.
  8. Make both StartPoints and Endpoints the only selectable layers. Use Zoom Out and the Selection tool or use the table to select all 47 points.
  9. In the Tools Menu, choose Macros > Macros > Select SplitLinesAtPoints and click Run. Review the summary windows to see how many points were used to split the road and how many splits occurred. This will actually split the road twice, using both Event Theme sets. Save the edits and the project.

Task 5: Assign Turn Numbers

Reload the Turn Chords layer and add the Middle Ordinate layer and make Chuckanut Ridge Road the only selectable layer. Use CR MP 0.01:3,000 to zoom to the south end of the road.

Use the Turn Chord layer as a guide to select the first turn segment. Either open an editing session to manually assign turn numbers or use the Field Calculator to populate the Turn_No field. Notice that ArcMap labels the segment as the number is assigned. Continue assigning numbers to all 47 turns. Although these turns do not have to be numbered sequentially, it does help keep turn numbers straight.

Finish the Project

When finished assigning numbers, open the attribute table and sort the turn numbers in ascending order. After assigning turn numbers, to reinforce an important point from the original tutorial, join the lengths of the Turn Chord and Middle Ordinate to each road segment. Next, calculate the radius of each turn and thematically map each using the color ramp used in the original exercise. Save the finished project.

Summary

This exercise is an extension of "Under Construction: Building and Calculating Turn Radii" in this issue. It teaches how to derive endpoints for polyline segments and how to use the points to split one or more polylines into smaller segments. This workflow has many uses beyond transportation engineering.

Acknowledgments

The author thanks Esri's Technical Support team for helping develop and deploy this method. An enhancement request has been submitted for this task and several related tasks that also surfaced while developing this exercise.

[an error occurred while processing this directive]