Select to view content in your preferred language

Return Geodatabase Feature Class Polyline Length in Feet and Miles

598
0
01-17-2019 08:04 PM
MapVis
by
Emerging Contributor

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);
                }
            });
           
        }
Tags (1)
0 Kudos
0 Replies