The most straightfoward thing is elusive:
All I want to do is create a spatially enable dataframe from an existing dataframe with a SHAPE column containing the respective arcpy Geometry objects.
I can create a SpatialDataFrame (deprecated apparently)
from arcpy.features import SpatialDataFrame
sdf = SpatialDataFrame(df, geometry='SHAPE').
That works, but in 1.5, I can't export to a feature class - I get the following error: The following rows could not be written to the table: 0,1,2,3........
So apparently I need to use a spatially enabled dataframe, but haven't figured out how to create one similar to above.
sdf = pd.DataFrame.spaital.from_df(df, geometry='SHAPE') doesn't work - error says got an unexpected argument geometry
sdf = pd.DataFrame.spaital.from_df(df) throws the error Address column not found in dataframe.
Anyone figured this out?
Where did the dataframe come from? Was it loaded from a service, feature class, etc...? Instead of converting a SpatialDataFrame to a Spatially-enabled DataFrame, why not just work with a spatially-enabled dataframe from the start of your code?
The dataframe is constructed from a variety of sources: csvs, other dataframes, shapefiles. After all the joining, merging, etc. etc., I get a dataframe back. Anyway, it seems that if you have a SHAPE field in the dataframe, it just works:
sdf = pd.DataFrame.spatial(df) #df has SHAPE field with geometry objects - don't know how this would work with a different field name
sdf.to_featureclass(mylocation)
What if my workflow is
1. Create new empty SEDF
2. Populate it
3. Save it
I need the equivalent of "df = SEDF()". At the moment it seems like the workflow needs to be something clumsily hacky like
1. Load an existing dataset as an SEDF
2. Empty it
3 Refill it
4 Save it
If I try to create a pd.DataFrame() and copy shapes into it and then write it out with to_featureclass it tells me to use "set_geometry" and if I do that then it fails.
Sometimes it tells me not to use SpatialDataFrames because they are deprecated, yet type(points) shows the dataset is a GeoAccessor.
Like everything else I've been trying, this almost works.
import pandas as pdfrom arcgis.geometry import Pointp = Point({"x":0,"y":0})df = pd.DataFrame({'OJECTID': [1,2,3], 'SHAPE':[p,p,p], 'name': ['Stitch', 'Harry', 'Phoebe']})df.spatial.set_geometry('SHAPE',sr=4326)df.spatial.validate(strict=True)df.spatial.to_featureclass(location="points.shp")
If the "ArcGIS API for Python" were an opensource project, it would be version < 1 -- then I'd find it more acceptable and cut some slack. Missing properties, missing methods, documentation errors... I'd just fix some of these and issue pull requests 🙂
If I issue a bug report it will be assigned some value like "3" and then Esri will say "we never fix anything with a priority below 1000". Or it will be changed from "bug" to "feature will not be implemented" and closed.
I certainly would run away from today if there were an alternative. I am thinking of trying geopandas?