Select to view content in your preferred language

While converting feature class to spatially enabled dataframe shape_length data is not populating ?

701
4
08-31-2023 02:43 AM
Labels (1)
NiharSahoo
New Contributor III

I am converting feature class to spatially enabled data frame using below code, after conversion shape_length field of a line layer is not getting populated. Only shape data is available ?

 

fc = os.path.join(geodatabase_path, layer_name)
sedf = arcgis.GeoAccessor.from_featureclass(fc)

 

0 Kudos
4 Replies
DavidPike
MVP Frequent Contributor

maybe a shapefile?

0 Kudos
NiharSahoo
New Contributor III

Sorry i could understand. Can you please elaborate ?

0 Kudos
DanPatterson
MVP Esteemed Contributor

A shapefile might retain the shape_length field.  Shape_length and shape_area are maintained by featureclasses (eg in a gdb), but the code for 

arcgis.GeoAccessor.from_featureclass

may not maintain it.  Look at the code in your installation for

C:\... your install dir ...\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\geo\_io\fileops.py

lines 666-682.  If you are running in an environment that has arcpy installed it attempts to read the length and area field... If your environment doesn't have arcpy installed, it will fail to retrieve them.


... sort of retired...
EarlMedina
Esri Regular Contributor

I am seeing this too. Looks like the SHAPE_LENGTH field does not come through with GDB feature classes, at least. The good news, however, is it's simple to re-calculate the Shape length field:

sedf["length"] = sedf["SHAPE"].apply(lambda x: x.get_length("PLANAR", "METERS"))

More information on get_length options here.

0 Kudos