AnsweredAssumed Answered

Create Line Feature Service from Spatial Dataframe

Question asked by s.geigenbergeresri-de-esridist Employee on Jan 23, 2018
Latest reply on Jan 23, 2018 by achapkowski-esristaff

I create a Spatial Dataframe with a line geometry in it. This should be published as a Feature Layer on ArcGIS Online but a error occures. 

 

1. Create a line geometry and add it to a list.

line = {
  "paths" : [[[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]],
             [[-97.06326,32.759],[-97.06298,32.755]]],
  "spatialReference" : {"wkid" : 4326}
}
polyline = geometry.Polyline(line)

listGeometries = []
listGeometries.append(polyline)

2. Create a pandas dataframe with additional information.

d = {'col1':["abc"], 'col2':[123]}
df = pd.DataFrame(d)

3. Create a Spatial Dataframe and a Feature Layer from this.

spatialDataFrame = fs.SpatialDataFrame(data=df, geometry=listGeometries)

spatialDataFrameLayer = spatialDataFrame.to_featurelayer("LineFeatureLayer")

This error message occures.

---------------------------------------------------------------------------KeyError                                  Traceback (most recent call last)<ipython-input-69-74d83f9ecb21> in <module>()----> 1 spatialDataFrameLayer = spatialDataFrame.to_featurelayer("MarienplatzProjected")      2 #spatialDataFrameLayer = spatialDataFrame.to_featureset()~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis
\features\_data\geodataset\geodataframe.py
in to_featurelayer(self, title, gis, tags)    899                 raise ValueError("GIS object must be provided")    900         content = gis.content--> 901         return content.import_data(self, title=title, tags=tags)    902     #----------------------------------------------------------------------    903     def set_geometry(self, col, drop=False, inplace=False, sr=None):~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis
\gis\__init__.py
in import_data(self, df, address_fields, **kwargs)   2332                                    uuid4().hex[:5])   2333                 ds = df.to_featureclass(out_location=temp_dir,-> 2334                                         out_name=name)   2335                 zip_shp = zipws(path=temp_dir, outfile=temp_zip, keep=False)   2336                 item = self.add( ~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis
\features\_data\geodataset\geodataframe.py
in to_featureclass(self, out_location, out_name,
overwrite, skip_invalid)
    616                                out_location=out_location,    617                                out_name=out_name,--> 618                                overwrite=overwrite, skip_invalid=skip_invalid)    619     #----------------------------------------------------------------------    620     def to_hdf(self, path_or_buf, key, **kwargs):~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis\
features\_data\geodataset\io\fileops.py
in to_featureclass(df, out_name, out_location, overwrite, out_sr, skip_invalid)    382         return _pyshp_to_shapefile(df=df,    383                                    out_path=out_location,--> 384                                    out_name=out_name)    385     else:    386         raise Exception("Cannot Export the data without ArcPy or PyShp modules. "+ \ ~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis
\features\_data\geodataset\io\fileops.py
in _pyshp_to_shapefile(df, out_path, out_name)     90                 shpfile.poly(geom['rings'])     91             elif geom.type == "Polyline":---> 92                 shpfile.line(geom['path'])     93             elif geom.type == "Point":     94                 shpfile.point(x=geom.x, y=geom.y)KeyError: 'path'

It seams, as the "paths" key in the first code snippet is the problem, because a "path" key is required. But if the "paths" is changed to "path" the line geometrie is nod valid anymore.

 

How can I publish valid line geometries as a Feature Layer?

 

Rohit Singh

Outcomes