Select to view content in your preferred language

(re)project geometry after spatial.from_feather()

248
1
12-30-2024 04:16 AM
Mer-lin
Emerging Contributor

hi,

after reading a feather file as described here

 

# Create SeDf by reading from feather
sdf_f = pd.DataFrame.spatial.from_feather(
    './sedf_data/cities/sample_cms_data.feather')

 

 we get a pandas DF.

calling

 

print(sdf_t.spatial.sr)

 

gives: {'wkid': None}

How could one (re)project the sdf?

0 Kudos
1 Reply
Marshal
Frequent Contributor

You can directly set the sr property of the spatial dataframe.

 

 

from arcgis import GeoAccessor
from arcgis.geometry import SpatialReference

# Create dataframe by reading from feather
df = GeoAccessor.from_feather(
    './sedf_data/cities/sample_cms_data.feather')

# Create spatially enabled dataframe (NAD27, EPSG 4267)
sdf_f = GeoAccessor.from_df(df, sr=4267, geometry_column='SHAPE')

# Directly set the spatial reference (WGS84, EPSG 4326) with no conversion
sdf_f.spatial.sr = SpatialReference(4326)

# Verify the spatial reference
print(sdf_f.spatial.sr)

 

Note, this is different projecting the dataframe from one spatial reference system to another.  In that case, you would use the .project() method to ensure proper conversion.

https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.G...

 

 

 

# Inplace projection to NAD27
sdf_f.spatial.project(4267)

 

 

 

 

0 Kudos