AnsweredAssumed Answered

Return Geodatabase Feature Class Polyline Length in Feet and Miles

Question asked by mapvis01 on Jan 17, 2019

This may be an easy question but looking through the pro sdk samples and guides I didn't see the optimal way of getting a geodatabase feature class length in feet or miles like the python below. How do you get a feature classes full length or selection records length from the @SHAPE fields while supplying the unit of measurement you want?

 

<code>

with arcpy.da.SearchCursor(lyr, ['SHAPE@']) as cursor:
                for row in cursor:
                    length += row[0].getLength("PLANAR", "FEET")
                    print("Total length: {0}".format(length))

</code>

 

similar to the code below but needing to specify the return unit of measurment

 

public static void GetLength(Map map, string layer)
        {
            QueuedTask.Run(() =>
            {
                FeatureLayer fl1 = map.FindLayers(layer).FirstOrDefault() as FeatureLayer;
                QueryFilter queryFilter = new QueryFilter();
                using (ArcGIS.Core.Data.RowCursor rowCursor = fl1.Search(queryFilter = null))
                {
                    
                    double length = 0;
                    while (rowCursor.MoveNext())
                    {
                       
                        Feature feature1 = rowCursor.Current as Feature;
                        Geometry geo = feature1.GetShape().Clone() as Polyline;
                        length += GeometryEngine.Instance.Length(geo);
                        Debug.WriteLine(length);
                    }
                    Debug.WriteLine("total: " + length/5280);
                }
            });
           
        }

Outcomes