Error Saving Feature Set

1393
14
01-17-2019 06:43 AM
by Anonymous User
Not applicable

I am trying to convert from a GEOJSON FeatureCollection to an Feature Class, using the Python API. The FeatureCollection contains a single point and a single polygon geometries.  The saving fails.  I suppose because of the mixed geometry?  Here is my code and the error:

geojson_file = r'C:\Users\XXX\Documents\Python_Scripts\SS_160_SnappedLoc_geoms.geojson'
with open(geojson_file) as f:
    geojson = json.load(f)
arc_conv_out = arcgis.features.FeatureSet.from_geojson(geojson)
arc_conv_out.save(r"C:\Users\xxx\Documents\Python_Scripts\SS_160_SnappedLoc_geoms.geojson", "test_out")


ERROR:

AttributeError: module 'arcpy' has no attribute 'JSONToFeatures_conversion'

Anyone have any ideas?

Tags (2)
0 Kudos
14 Replies
JoshuaBixby
MVP Esteemed Contributor

Thomas Taggart‌, taking my code from above and using your overall approach, I am able to make it work.  Although the inclusion of "crs" will generate a warning, it does not generate an error so I leave it.  Also, the ArcGIS API for Python doesn't seem to mind if the ring order is reversed, so I left that as well.

>>> geojson = {
...     "crs": {"type": "ESPG", "properties": {"code": 4326}},
...     "type": "FeatureCollection",
...     "features": [
...         {
...             "properties": {"FID": 0, "OBJECTID": 1},
...             "type": "Feature",
...             "geometry": {
...                 "type": "Point",
...                 "coordinates": [-71.9699842506338, 43.654311975352826]
...             }
...         },
...         {
...             "properties": {"FID": 0, "OBJECTID": 1},
...             "type": "Feature",
...             "geometry": {
...                 "type": "Polygon",
...                 "coordinates": [[
...                     [-71.97037911846795, 43.65394056313409],
...                     [-71.9709458777763, 43.65393905593083],
...                     [-71.97094629332796, 43.65402135769166],
...                     [-71.9710596450912, 43.654021055913624],
...                     [-71.97106006079942, 43.6541033576724]
...                 ]]
...             }
...         }
...     ]
... }
>>> 
>>> geojson["features"] = [
...     feat for feat
...     in geojson["features"] 
...     if feat["geometry"]["type"] == "Polygon"
... ]
>>> 
>>> from arcgis.features import FeatureSet
>>> fs = FeatureSet.from_geojson(geojson)
>>> fs.save("/tmp", "features")
'/tmp/features.shp'
>>> 
by Anonymous User
Not applicable

So, that all works for me up until the save when I get this error:

  File "C:/Users/Thomas.p.Taggart/Documents/Python_Scripts/Geojson_SHP_convert.py", line 17, in <module>
    fs.save("","Test.shp")
  File "C:\Python37\lib\site-packages\arcgis\features\feature.py", line 1093, in save
    out_fc=os.path.join(save_location, out_name))
  File "C:\Python37\lib\site-packages\arcgis\_impl\common\_spatial.py", line 22, in json_to_featureclass
    return arcpy.JSONToFeatures_conversion(in_json_file=json_file,
AttributeError: module 'arcpy' has no attribute 'JSONToFeatures_conversion'

So, I am trying to access the ArcPy installation that arrived with ArcGIS Pro, but must be failing to correct access it?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Yes, your error message indicates that ArcPy is not properly loaded.  Are you using the ArcGIS API for Python that comes with ArcGIS Pro?

0 Kudos
by Anonymous User
Not applicable

I am trying, but it appears that I am not.   I have been executing this outside ArcGIS in Pycharm, my preferred IDE, but I suppose I should just execute it inside ArcGIS Pro to be able to definitely access ArcPy.   

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I use PyCharm regularly with the Python installation bundled with Pro, so I know it is possible.  I would try running the code from within the application just to see if it works.  If it does, then you know you need to sort out your PyCharm configuration before moving forward.  If it doesn't work in the application, then something might be messed up with your Pro installation.

0 Kudos