Hello,
I have a shapefile that contains one line, and I need to extract the "Shape Length" value from his attribute table using python.
Any suggestion?
a search cursor will do the trick SearchCursor—ArcGIS Pro | Documentation
import arcpy fc = 'c:/data/your_shapefile.shp' #look at the geometry tokens in the help url #for more understanding fields = ['SHAPE@LENGTH'] #open cursor with arcpy.da.SearchCursor(fc, fields) as cursor: #for every row in the shapefiles attribute table for row in cursor: #row[0] is the first field specified when opening the cursor #next field rould be row[1]...etc #print the length print(row[0])
if there is a method to calculate the length of the polyline also it can work.
I only need the value of the "shape length" cell. Then, I will use this value in the script.
Where do you want to extract it to?
Using Python Parser of Field Calculator?
!shape.length@<units>!
e.g.: For calculating length in yards
!shape.length@yards!
Geometry Calculation
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.