Select to view content in your preferred language

Projected Spatial Dataframe to Feature Layer

1552
0
01-23-2018 05:53 AM
SimonGeigenberger
Occasional Contributor

The following steps explain my workflow to create a Feature Layer from a Spatial Dataframe. Also the coordinates should be projected in another coordinate system.

1. Create a point located in Munich with WGS 84 coordinates and add it to a list.

dictSpatialReference = {}
dictPoint = {}

x = 11.575442
y = 48.137141
wkid = 4326

dictSpatialReference["wkid"] = wkid

dictPoint["x"] = x
dictPoint["y"] = y
dictPoint["spatialReference"] = dictSpatialReference

pt = geometry.Point(dictPoint)‍‍‍‍‍‍‍‍‍‍‍‍‍‍

listGeometries = []
listGeometries.append(pt)

2. Create a pandas dataframe with aditional information.

d = {'name':["Marienplatz"], 'city':["Munich"]}
df = pd.DataFrame(d)

Next a Spatial Dataframe is created and a Feature Layer is published. The coordinates should be transformed in the DHDN_3_Degree_Gauss_Zone_4 coordinate system (WKID: 31468) that is a projected coordinate system for Germany. To achieve this, two different ways are implemented.

1. Project the geometries, create a Spatial Dataframe and publish a Feature Layer.

listGeometriesProjected = geometry.project(listGeometries, 4326, 31468)
spatialDataFrame = fs.SpatialDataFrame(data=df, geometry=listGeometriesProjected)‍‍
spatialDataFrameLayer = spatialDataFrame.to_featurelayer("MarienplatzProjected")

The coordinates are projected correctly and the Spatial Dataframe is created. The result of the "to_featurelayer()" method is this error message.

Exception                                 Traceback (most recent call last)<ipython-input-61-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)   2345                 if target_sr is not None:   2346                     publish_parameters['targetSR'] = { 'wkid' : target_sr }-> 2347                 return item.publish(publish_parameters=publish_parameters)   2348             return   2349         elif isinstance(df, pd.DataFrame):~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis\gis
\__init__.py in publish(self, publish_parameters, address_fields, output_type, overwrite, file_type)   5426             except: pass   5427         else:-> 5428             serviceitem_id = self._check_publish_status(ret, folder)   5429         return Item(self._gis, serviceitem_id)   5430  ~\AppData\Local\Continuum\Anaconda3\envs\arcgis\lib\site-packages\arcgis-1.3.0-py3.5.egg\arcgis\gis
\__init__.py in _check_publish_status(self, ret, folder)   5660                     #print(str(job_response))   5661                     if job_response.get("status") in ("esriJobFailed","failed"):-> 5662                         raise Exception("Job failed.")   5663                     elif job_response.get("status") == "esriJobCancelled":   5664                         raise Exception("Job cancelled.")Exception: Job failed.

2. Create a Spatial Dataframe with the WGS84 coordinates and use the "reproject()" method.

spatialDataFrame = fs.SpatialDataFrame(data=df, geometry=listGeometries)
spatialDataFrameProjected = spatialDataFrame.reproject(31468, transformation=None, inplace=False)

Using the reproject method does not change anything and the coordinates and spatial reference system are still WGS84.

How can I project a Spatial Dataframe and publish the data with the chosen coordinate system as a Feature Layer?

rsingh-esristaff

0 Kudos
0 Replies