How To: Create a PolylineM theme and add measurement values


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.


  1. Add the Polyline shapefile you wish to covert to a view and make it the active theme.
  2. Open a new script window.
    A. Activate the Project window.
    B. Click the Scripts icon.
    C. 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...")
    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 
      theNewFtab = Ftab.MakeNew(theNewShapefile,PolyLineM)
      '-- Populate the new shapefile with Fields ..
      theFieldList.RemoveObj(theShapeField) '-- ignore the shape field
      theFieldCount = theFieldList.Count - 1
      theNewShapeField = theNewFtab.FindField("shape")
      theNewFieldList = theFieldList.DeepClone
      '-- 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
        For each fld in (0..theFieldCount)
          theVal = theFtab.ReturnValue(theFieldList.Get(fld),rec)
      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")
    End   '-- If (theClassName = "PolyLine") ...
    '-- 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)
     All of the resulting measurement values will be null 
  4. Attach the script to a new button.
    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog box, click the Type dropdown arrow and click View.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Type the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see "Customize dialog box" in ArcView Help.
  5. Switch to the view and click the newly added button.
  6. Specify a name for the new PolylineM shapefile and choose to add it to the view.
  7. Make the PolylineM theme active and select Start Editing from the View menu.
    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.
    1. Click Script > Load System Script. Navigate to the View.ToggleEditingUpdate script and click OK.
    2. Add the 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"))
    3. Click on Script > Compile.
    4. Rename the script View.ToggleEditingUpdate.
      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.
    5. 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
    6. 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
    7. Click OK on both dialog boxes.
    8. Open the PolylineM shapefile attribute table. One feature should be highlighted in the table.
    9. Make the shape field active.
    10. Select Calculate from the Field menu.
    11. Enter the following code in the expression text box on the Filed Calculator dialog box.
       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 . . .
    12. Repeat the above steps for each feature in the shapefile.