Select to view content in your preferred language

# ArcGIS Pro M value tools: Is "Set Direction As M" in arcpy?

463
2
04-20-2023 02:10 PM
Occasional Contributor

ArcGIS Pro has tools for working with M values. Are these functionalities available in arcpy?

Tags (3)
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Think you'll have to do it manually with a cursor and extracting the m from the point.  Stealing a post from SO

``````lyr = r"C:\Users\...\Default.gdb\TEST_ROUTE"
fields = ['SHAPE@']

with arcpy.da.UpdateCursor(lyr, fields) as cursor:
for row in cursor:
partslist = []
partlist = []
array = None
feat = row[0]
partnum = 0

# Count the number of points in the current multipart feature
partcount = feat.partCount
pntcount = 0

# Enter while loop for each part in the feature (if a singlepart feature
# this will occur only once)
#
while partnum < partcount:
part = feat.getPart(partnum)
pnt = part.next()

# Enter while loop for each vertex
#
while pnt:
pntcount += 1
if not numpy.isnan(pnt.M):
partlist.append(arcpy.Point(pnt.X, pnt.Y, pnt.Z, pnt.M / 1000))
pnt = part.next()

# If pnt is null, either the part is finished or there is an
# interior ring
#
if not pnt:
pnt = part.next()
partslist.append(arcpy.Array(partlist))
array = arcpy.Array(partslist)
partlist = []
partnum += 1
polylinefeat = arcpy.Polyline(array)
row[0] = polylinefeat
cursor.updateRow(row)``````

2 Replies
by Anonymous User
Not applicable

Think you'll have to do it manually with a cursor and extracting the m from the point.  Stealing a post from SO

``````lyr = r"C:\Users\...\Default.gdb\TEST_ROUTE"
fields = ['SHAPE@']

with arcpy.da.UpdateCursor(lyr, fields) as cursor:
for row in cursor:
partslist = []
partlist = []
array = None
feat = row[0]
partnum = 0

# Count the number of points in the current multipart feature
partcount = feat.partCount
pntcount = 0

# Enter while loop for each part in the feature (if a singlepart feature
# this will occur only once)
#
while partnum < partcount:
part = feat.getPart(partnum)
pnt = part.next()

# Enter while loop for each vertex
#
while pnt:
pntcount += 1
if not numpy.isnan(pnt.M):
partlist.append(arcpy.Point(pnt.X, pnt.Y, pnt.Z, pnt.M / 1000))
pnt = part.next()

# If pnt is null, either the part is finished or there is an
# interior ring
#
if not pnt:
pnt = part.next()
partslist.append(arcpy.Array(partlist))
array = arcpy.Array(partslist)
partlist = []
partnum += 1
polylinefeat = arcpy.Polyline(array)
row[0] = polylinefeat
cursor.updateRow(row)``````

Occasional Contributor

This seems to do what I want. Thank you!