Select to view content in your preferred language

Calibrate m from attribute table

1144
5
08-17-2011 12:36 PM
RickCrawford
Deactivated User
I can�??t figure out how to do something in Arc 10 I use to be able to do in Arc 8X �?? 9X. What I need to do is Calibrate (Re-Calibrate) the M values on a selected set of routes based on two attribute values in the Route Feature classes attribute table. The attribute columns I�??m using are numeric fields and are named �??BMP" (Beginning Mile Post) and "EMP" (Ending Mile Post). I us to be able to do this with a VBA field calculator script. Here is the old VBA script I use to use.

dim pms as imsegmentation
set pms = [Shape]
pms.setandinterpolatemsbetween [BMP], [EMP]
dim pg as igeometry
set pg = pms

pg

Can anyone tell me if there is a way to basically do the same thing in ArcGIS 10. It can be Python or other method. I need to be able to write the new M values back to the original routes, and not create a new feature class. If it matters our Route feature classes are in SDE.

Rick Crawford USDA Forest Service
Tags (2)
0 Kudos
5 Replies
JacobPetrosky
Deactivated User
Posted the below at forum post 34274. 

I do not think it is possible to remeasure routes via the field calculator using python or VBA.

However, you could use a script similar to the following to recalculate m values for an existing route feature class. I would change the reference to the feature class and to/from fields and run it in IDLE or PythonWin. It simulates the functionality of the setandinterpolatemsbetween arcobjects command.

import arcpy
arcpy.env.overwriteOutput=1
inFC = r'C:\GIS\IncidentData\November\982292_Setandinterpolatemsbetween\test.gdb\routes_w_MPs' #Update path to the feature class
toField = "BEGMP1" #Update name of the To Measure Field
fromField = "ENDMP1" #Update name of the From Measure Field
desc = arcpy.Describe(inFC)
shapeField = desc.shapeFieldName
oidField = desc.OIDFieldName
oidQueryName = arcpy.AddFieldDelimiters(inFC, oidField)
g = arcpy.Geometry()
#Create update cursor on input feature class
rows = arcpy.UpdateCursor(inFC)
#Make feature layer from input feature class
arcpy.MakeFeatureLayer_management(inFC, "featureLayer")

#loop through rows in feature layer and select each OID
for row in rows:
arcpy.SelectLayerByAttribute_management("featureLayer", "New_Selection", oidQueryName + "=" + str(row.getValue(oidField)))
#create geometry object from each feature row
geomList = arcpy.CreateRoutes_lr("featureLayer", toField, g, "TWO_FIELDS", fromField, toField)
#update shape field for input feature class for each row (replace M values)
row.setValue(shapeField, geomList[0])
rows.updateRow(row)

arcpy.Delete_management("featureLayer")
del row, rows

Many thanks to Chris F. in Redlands for creating this.
0 Kudos
JacobPetrosky
Deactivated User
0 Kudos
RichardFairhurst
MVP Alum
Jacob:

Do you know if the method you used would preserve circular, elliptical and bezier polyline geometries?  I know that most attempts to use arcpy to deal with such geometries at the segment level result in loss of this type geometry information.  I need to query each point X,Y,Z and M values and part segment lengths in a polyline rather than just interpolate from the ends and need to preserve the non-linear geometries.  Can this be done in arcpy, or is that only possible in ArcObjects.  (The help suggests that arcpy cannot be used to access low level geometries, so I tend to think the answer is no).
0 Kudos
JacobPetrosky
Deactivated User
Richard,

I do not know a way to work with the non-linear geometries in arcpy.  I would suspect, as you have, that it is not possible.  I would start a new forum thread and ask (if you haven't already).  If you don't get an answer you can always submit an idea at http://ideas.arcgis.com.
0 Kudos
JacobPetrosky
Deactivated User
Posted the below at forum post 34274. 

I do not think it is possible to remeasure routes via the field calculator using python or VBA.

However, you could use a script similar to the following to recalculate m values for an existing route feature class. I would change the reference to the feature class and to/from fields and run it in IDLE or PythonWin. It simulates the functionality of the setandinterpolatemsbetween arcobjects command.

import arcpy
arcpy.env.overwriteOutput=1
inFC = r'C:\GIS\IncidentData\November\982292_Setandinterpolatemsbetween\test.gdb\routes_w_MPs' #Update path to the feature class
toField = "BEGMP1" #Update name of the To Measure Field
fromField = "ENDMP1" #Update name of the From Measure Field
desc = arcpy.Describe(inFC)
shapeField = desc.shapeFieldName
oidField = desc.OIDFieldName
oidQueryName = arcpy.AddFieldDelimiters(inFC, oidField)
g = arcpy.Geometry()
#Create update cursor on input feature class
rows = arcpy.UpdateCursor(inFC)
#Make feature layer from input feature class
arcpy.MakeFeatureLayer_management(inFC, "featureLayer")

#loop through rows in feature layer and select each OID
for row in rows:
arcpy.SelectLayerByAttribute_management("featureLayer", "New_Selection", oidQueryName + "=" + str(row.getValue(oidField)))
#create geometry object from each feature row
geomList = arcpy.CreateRoutes_lr("featureLayer", toField, g, "TWO_FIELDS", fromField, toField)
#update shape field for input feature class for each row (replace M values)
row.setValue(shapeField, geomList[0])
rows.updateRow(row)

arcpy.Delete_management("featureLayer")
del row, rows

Many thanks to Chris F. in Redlands for creating this.


Slight modifications to the script.  See below:

import arcpy
arcpy.env.overwriteOutput=1
inFC = r"C:\GIS\IncidentData\November\982292_Setandinterpolatemsbetween\UserData\PwkTransportationFDSCopyNovember2011.gdb\RouteCopySubsetNov2" #Update path to the feature class
toField = "MILEMARKER_END" #Update name of the To Measure Field
fromField = "MILEMARKER_BEGIN" #Update name of the From Measure Field
routeID = "ROUTEID" #Update name of Route ID field
desc = arcpy.Describe(inFC)
shapeField = desc.shapeFieldName
print shapeField
oidField = desc.OIDFieldName
print oidField
oidQueryName = arcpy.AddFieldDelimiters(inFC, oidField)
g = arcpy.Geometry()
#Create update cursor on input feature class
rows = arcpy.UpdateCursor(inFC)
#Make feature layer from input feature class
arcpy.MakeFeatureLayer_management(inFC, "featureLayer")

#loop through rows in feature layer and select each OID
for row in rows:
    arcpy.SelectLayerByAttribute_management("featureLayer", "New_Selection", oidQueryName + "=" + str(row.getValue(oidField)))
    #create geometry object from each feature row
    geomList = arcpy.CreateRoutes_lr("featureLayer", routeID, g, "TWO_FIELDS", fromField, toField)
    #update shape field for input feature class for each row (replace M values)
    row.setValue(shapeField, geomList[0])
    rows.updateRow(row)

arcpy.Delete_management("featureLayer")
del row, rows
0 Kudos