SpatialDataFrame has been deprecated. Please switch to the GeoAccessor/GeoSeriesAccessor.

884
2
Jump to solution
04-18-2020 08:45 AM
artzaifman
New Contributor III

How do I rewrite to eliminate warning below?

sdf_ = features.SpatialDataFrame(geometry=lines)
print(type(sdf_.spatial))

<class 'arcgis.features.geo._accessor.GeoAccessor'>
/Users/zaifmar/anaconda3/lib/python3.7/site-packages/arcgis/features/_data/geodataset/geodataframe.py:221: UserWarning: SpatialDataFrame has been deprecated.  Please switch to the GeoAccessor/GeoSeriesAccessor.   warnings.warn("SpatialDataFrame has been deprecated.  Please switch to the GeoAccessor/GeoSeriesAccessor.")
0 Kudos
1 Solution

Accepted Solutions
artzaifman
New Contributor III

Thanks Dan and just added the warning suppression to my code.

Also, here's how I avoided using deprecated SpatialDataFrame class:

sdf_A = GeoAccessor.from_xy(df_A, "x", "y", sr=102100)
sdf_B = GeoAccessor.from_xy(df_B, "x", "y", sr=102100)

lines = []
for i in range(len(sdf_A)):
   a = sdf_A.iloc["SHAPE"]
   b = sdf_B.iloc["SHAPE"]
   line = {
      "paths": [
         [
            [a.coordinates()[0], a.coordinates()[1]],
            [b.coordinates()[0], b.coordinates()[1]],
         ]
      ],
      "spatialReference": a.spatialReference,
   }
   lines.append(geometry.Polyline(line))

# sdf_lines = features.SpatialDataFrame(geometry=lines)
sdf_AB = sdf_A
sdf_AB["SHAPE_"] = lines
# sdf_AB["SHAPE_"] = sdf_lines["SHAPE"]

sdf_A.spatial.set_geometry("SHAPE_")
sdf_A.spatial.geometry_type

View solution in original post

0 Kudos
2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

you need to add code to suppress warnings.. with the warning, that the deprecation warning won't last for many arcgis versions, so you should begin to move on.

From here

How to disable python warnings - Stack Overflow 

import sys
import warnings

if not sys.warnoptions:
    warnings.simplefilter("ignore")
artzaifman
New Contributor III

Thanks Dan and just added the warning suppression to my code.

Also, here's how I avoided using deprecated SpatialDataFrame class:

sdf_A = GeoAccessor.from_xy(df_A, "x", "y", sr=102100)
sdf_B = GeoAccessor.from_xy(df_B, "x", "y", sr=102100)

lines = []
for i in range(len(sdf_A)):
   a = sdf_A.iloc["SHAPE"]
   b = sdf_B.iloc["SHAPE"]
   line = {
      "paths": [
         [
            [a.coordinates()[0], a.coordinates()[1]],
            [b.coordinates()[0], b.coordinates()[1]],
         ]
      ],
      "spatialReference": a.spatialReference,
   }
   lines.append(geometry.Polyline(line))

# sdf_lines = features.SpatialDataFrame(geometry=lines)
sdf_AB = sdf_A
sdf_AB["SHAPE_"] = lines
# sdf_AB["SHAPE_"] = sdf_lines["SHAPE"]

sdf_A.spatial.set_geometry("SHAPE_")
sdf_A.spatial.geometry_type

0 Kudos