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.
'-- 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
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.
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"))
Note: Start Editing under the Theme menu will now be enabled.
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 . . .