HOW TO

Create a PolylineM theme and add measurement values

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS GIS 3.x only. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

This document describes how to convert a PolyLine shapefile into a PolylineM shapefile and add a measurement value to each vertex. You must know the M values for the start and end vertices of each feature. They can not be automatically calculated.

Procedure

  1. Add the Polyline shapefile you wish to covert to a view and make it the active theme.
  2. Open a new script window.
    1. Activate the Project window.
    2. Click the Scripts icon.
    3. Click New.
  3. Paste the following code into the new script windows.
'-- This is a simple script that will convert a PolyLine theme to a PolyLineM 
'-- theme. The measures will not be explicitly set and will, therefore, all be 
'-- Null Numbers. You can use the field calculator along with requests such as
'-- SetMAsLength to add measure values.

'-- You can add this script to a button in the View as a CLICK script. Only 
'-- the first active theme will be processed. The active theme must be PolyLine.

'-- Any selected set will be ignored by this script.

'-- Get the active theme ...

theView = av.GetActiveDoc 
theCount = theView.GetActiveThemes.Count
If (theCount = 0) then
  msgbox.info("There is no active theme to process.","No active theme...")
  exit
End
theTheme = theView.GetActiveThemes.Get(0)  
theFtab = theTheme.GetFtab     
theClassName = theFtab.GetShapeClass.GetClassName.AsString

'-- Only proceed with the active theme if it is PolyLine ...  

If (theClassName = "PolyLine") then 
  theFieldList = theFtab.GetFields.Clone 

  theShapeField = theFtab.FindField("shape")

  '-- Create a new shapefile with fields ...
  
  theNewShapefile = Filedialog.Put("*.shp".AsFilename,"*.shp",
    "Enter new shapefile name for "+theTheme.GetName)
  If (theNewShapefile = nil)  then 
    exit
  End      
  theNewFtab = Ftab.MakeNew(theNewShapefile,PolyLineM)
  theNewFtab.StartEditingWithRecovery
  '-- Populate the new shapefile with Fields ..
   
  theFieldList.RemoveObj(theShapeField) '-- ignore the shape field

  theFieldCount = theFieldList.Count - 1
  theNewShapeField = theNewFtab.FindField("shape")
  theNewFieldList = theFieldList.DeepClone
  theNewFtab.AddFields(theNewFieldList)

  '-- Convert the PolyLines to PolyLineMs and add the measures ...
  
  For each rec in theFtab
    theShape = theFtab.ReturnValue(theShapeField,rec) 
    theShapeM = theShape.AsPolyLineM
         
    '-- Get the attributes back ...  
    
    theNewRecnum = theNewFtab.AddRecord
    theNewFtab.SetValue(theNewShapeField,theNewRecnum,theShapeM)

    For each fld in (0..theFieldCount)
      theVal = theFtab.ReturnValue(theFieldList.Get(fld),rec)
      theNewFtab.SetValue(theNewFieldList.Get(fld),theNewRecnum,theVal)
    End
  End  '-- For each rec...  
Else   '-- If the current theme is not a PolyLine theme ...
  msgbox.info (theTheme.GetName+" is a "+theClassName.AsString+" theme is not a PolyLine theme.",  theTheme.GetName+" is not a PolyLine theme")
  exit
End   '-- If (theClassName = "PolyLine") ...
theNewFtab.StopEditingWithRecovery(true)

'-- Add the new shapefile to the view if the user wants...

If (MsgBox.YesNo("Add shapefile as theme to the view?",
    "Convert to Shapefile",true)) then 
  newFtheme = Ftheme.Make(theNewFtab)
  theView.Addtheme(newFtheme)
  newFtheme.Setvisible(true)      
End
Note:
 All of the resulting measurement values will be null 
  1. Attach the script to a new button.
    1. Compile the script.
    2. Switch to the Project window.
    3. Select Customize from the Project menu.
    4. On the Customize dialog box, click the Type drop-down arrow and click View.
    5. Select Buttons under Category.
    6. Click the New button.
    7. Double-click the Click property in the Customize dialog box.
    8. Type the name of the script in the Script Manager and click Select.
    9. Close the Customize dialog box.
      For more information, see "Customize dialog box" in ArcView Help.
  2. Switch to the view and click the newly added button.
  3. Specify a name for the new PolylineM shapefile and choose to add it to the view.
  4. Make the PolylineM theme active and select Start Editing from the View menu.
Note:
By default, ArcView can not edit 3D shapefiles. If you have 3D Analyst turn the extension on. Otherwise you will need to make some modifications to one of ArcView's system scripts.

Before beginning, please be aware that the procedure outlined in the following document is not supported. The only supported method of enabling editing on 3D shapefiles is using 3D Analyst extension. The steps below explain how to customize the system script 'View.ToggleEditingUpdate' so that you are able to start editing on PolylineM shapefiles.

  1. Open a new script window.
    1. Activate the Project window.
    2. Click the Scripts icon.
    3. Click New.
  2. Click Script > Load System Script. Navigate to the View.ToggleEditingUpdate script and click OK.
  3. Add the following text.:
or (clsName = "PolylineM")

to the following line of code:

if ((clsName = "Point") or (clsName = "PolyLine") or (clsName = "Polygon") or (clsName = "GeoEvent"))

The resulting code should look like:

if ((clsName = "Point") or (clsName = "PolyLine") or (clsName = "Polygon") or (clsName = "PolyLineM") or (clsName = "GeoEvent"))
  1. Click Script > Compile.
  2. Rename the script View.ToggleEditingUpdate.
Note:
Start Editing under the Theme menu will now be enabled.
  1. Select Properties from the Script menu.
  2. Type in a new name in the Name field.
  3. Click OK.
  4. Once in edit mode, select a PolylineM feature, right-click and select shape properties from the pop-up menu. Count the number of vertices in the shape.
[O-Image] shapeproperties
  1. Click the Edit button, manually edit the M values for the start and end vertices. (You will need to know these values beforehand.)
[O-Image] PolyLineM Vertex Point Edit
  1. Click OK on both dialog boxes.
  2. Open the PolylineM shapefile attribute table. One feature should be highlighted in the table.
  3. Make the shape field active.
  4. Select Calculate from the Field menu.
  5. Enter the following code in the expression text box on the Field Calculator dialog box.
[Shape].interpolatembetween({0,n})
Note:
 n is the number of vertices in the feature minus 1. For example, if there were 68 vertices listed in shape properties, it would read . . .
[Shape].interpolatembetween({0,67})
  1. Repeat the above steps for each feature in the shapefile.

Article ID:000002542

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic