Skip to main content
Notice removed Draw attention by User1974
Bounty Ended with Thomas's answer chosen by User1974
deleted 1021 characters in body
Source Link
User1974
  • 198
  • 1
  • 19
 

How can the script be improved?


Edit:

I have a different version of the script that is very similar, except it's purpose is just to print out the hierarchical components of the polyline geometry:

import arcpy
connection = "Database Connections\my_conn.sde"
feature_class = connection + "\my_owner.my_fc"

with arcpy.da.SearchCursor(feature_class, ["SHAPE@","OID@"]) as cursor:
    for row in cursor:
        geometry = row[0]
        print("Geometry/Polyline: {}".format(row[1]))
        for i, part in enumerate(geometry):
            print("  Part: {}".format(i))
            for j, point in enumerate(part):
                print("    Point: {}".format(j))

>>> 
Geometry/Polyline: 100
  Part: 0
    Point: 0
    Point: 1
    Point: 2
    Point: 3
    Point: 4
  Part: 1
    Point: 0
    Point: 1

How does that sister script look?

Feel free to let me know if it should be it's own question.

How can the script be improved?


Edit:

I have a different version of the script that is very similar, except it's purpose is just to print out the hierarchical components of the polyline geometry:

import arcpy
connection = "Database Connections\my_conn.sde"
feature_class = connection + "\my_owner.my_fc"

with arcpy.da.SearchCursor(feature_class, ["SHAPE@","OID@"]) as cursor:
    for row in cursor:
        geometry = row[0]
        print("Geometry/Polyline: {}".format(row[1]))
        for i, part in enumerate(geometry):
            print("  Part: {}".format(i))
            for j, point in enumerate(part):
                print("    Point: {}".format(j))

>>> 
Geometry/Polyline: 100
  Part: 0
    Point: 0
    Point: 1
    Point: 2
    Point: 3
    Point: 4
  Part: 1
    Point: 0
    Point: 1

How does that sister script look?

Feel free to let me know if it should be it's own question.

 

How can the script be improved?

added 820 characters in body
Source Link
User1974
  • 198
  • 1
  • 19

 

How can the script be improved?


Edit:

I have a different version of the script that is very similar, except it's purpose is just to print out the hierarchical components of the polyline geometry:

import arcpy
connection = "Database Connections\my_conn.sde"
feature_class = connection + "\my_owner.my_fc"

with arcpy.da.SearchCursor(feature_class, ["SHAPE@","OID@"]) as cursor:
    for row in cursor:
        geometry = row[0]
        print("Geometry/Polyline: {}".format(row[1]))
        for i, part in enumerate(geometry):
            print("  Part: {}".format(i))
            for j, point in enumerate(part):
                print("    Point: {}".format(j))

>>> 
Geometry/Polyline: 100
  Part: 0
    Point: 0
    Point: 1
    Point: 2
    Point: 3
    Point: 4
  Part: 1
    Point: 0
    Point: 1

How does that sister script look?

Feel free to let me know if it should be it's own question.


 

How can the script be improved?

How can the script be improved?


Edit:

I have a different version of the script that is very similar, except it's purpose is just to print out the hierarchical components of the polyline geometry:

import arcpy
connection = "Database Connections\my_conn.sde"
feature_class = connection + "\my_owner.my_fc"

with arcpy.da.SearchCursor(feature_class, ["SHAPE@","OID@"]) as cursor:
    for row in cursor:
        geometry = row[0]
        print("Geometry/Polyline: {}".format(row[1]))
        for i, part in enumerate(geometry):
            print("  Part: {}".format(i))
            for j, point in enumerate(part):
                print("    Point: {}".format(j))

>>> 
Geometry/Polyline: 100
  Part: 0
    Point: 0
    Point: 1
    Point: 2
    Point: 3
    Point: 4
  Part: 1
    Point: 0
    Point: 1

How does that sister script look?

Feel free to let me know if it should be it's own question.

deleted 60 characters in body
Source Link
User1974
  • 198
  • 1
  • 19

I have a Python 2.7 script that loops through GIS polylines and updates a coordinate.

The coordinate is called an "M" coordinate (aka a "Measure-value"). M coordinates are similar to X and Y coordinates, but are used for specialized linear referencing purposes.

enter image description here

More info: Set M-values to cumulative length of line

import arcpy
connection = "Database Connections\my_conn.sde"
fc = connection + "\my_owner.my_fc"
spatialRef = arcpy.Describe(fc).spatialReference

with arcpy.da.Editor(connection) as editSession:
    with arcpy.da.UpdateCursor(fc, ["ASSET_ID", "SHAPE@"]) as cursor:
        for row in cursor:
            feature = row[1].densify ("ANGLE", 10000, 0.174533)
            partNum = 0
            partArray = arcpy.Array()
            for part in feature:
                pointArray = arcpy.Array()
                n = len(part)
                for i in range(n):
                    point = part.getObject(i)
                    point.M = feature.measureOnLine(point)
                    pointArray.append(point)
                partArray.append(pointArray)
                partNum += 1
            row[1] = arcpy.Polyline(partArray, spatialRef)
            cursor.updateRow(row)

How can the script be improved?

I have a Python 2.7 script that loops through GIS polylines and updates a coordinate.

The coordinate is called an "M" coordinate (aka a "Measure-value"). M coordinates are similar to X and Y coordinates, but are used for specialized linear referencing purposes.

enter image description here

More info: Set M-values to cumulative length of line

import arcpy
connection = "Database Connections\my_conn.sde"
fc = connection + "\my_owner.my_fc"
spatialRef = arcpy.Describe(fc).spatialReference

with arcpy.da.Editor(connection) as editSession:
    with arcpy.da.UpdateCursor(fc, ["ASSET_ID", "SHAPE@"]) as cursor:
        for row in cursor:
            feature = row[1].densify ("ANGLE", 10000, 0.174533)
            partNum = 0
            partArray = arcpy.Array()
            for part in feature:
                pointArray = arcpy.Array()
                n = len(part)
                for i in range(n):
                    point = part.getObject(i)
                    point.M = feature.measureOnLine(point)
                    pointArray.append(point)
                partArray.append(pointArray)
                partNum += 1
            row[1] = arcpy.Polyline(partArray, spatialRef)
            cursor.updateRow(row)

How can the script be improved?

I have a Python 2.7 script that loops through GIS polylines and updates a coordinate.

The coordinate is called an "M" coordinate (aka a "Measure-value"). M coordinates are similar to X and Y coordinates, but are used for specialized linear referencing purposes.

enter image description here

import arcpy
connection = "Database Connections\my_conn.sde"
fc = connection + "\my_owner.my_fc"
spatialRef = arcpy.Describe(fc).spatialReference

with arcpy.da.Editor(connection) as editSession:
    with arcpy.da.UpdateCursor(fc, ["ASSET_ID", "SHAPE@"]) as cursor:
        for row in cursor:
            feature = row[1].densify ("ANGLE", 10000, 0.174533)
            partNum = 0
            partArray = arcpy.Array()
            for part in feature:
                pointArray = arcpy.Array()
                n = len(part)
                for i in range(n):
                    point = part.getObject(i)
                    point.M = feature.measureOnLine(point)
                    pointArray.append(point)
                partArray.append(pointArray)
                partNum += 1
            row[1] = arcpy.Polyline(partArray, spatialRef)
            cursor.updateRow(row)

How can the script be improved?

Notice added Draw attention by User1974
Bounty Started worth 50 reputation by User1974
deleted 37 characters in body
Source Link
User1974
  • 198
  • 1
  • 19
Loading
Source Link
User1974
  • 198
  • 1
  • 19
Loading