2

I rarely use ArcGIS Online but I have been tasked to download all layers on this https://services5.arcgis.com/gFh7gtZrHd449arT/arcgis/rest/services/greenez514_SW5_District_Layers/FeatureServer

I found some code I am mirroring but I keep getting an error here

import arcgis
from arcgis.gis import GIS
gis = GIS(None,'', '', verify_cert=False)
service = gis.content.get('f6325cf72860419b8f75bae4259344a5')
print(service.title)
result = service.export('  {}'.format(service.title), 'File Geodatabase', parameters=None, wait=True) 

this is the error I get

SW5 District Layers
Traceback (most recent call last):
  File "disagree.py", line 8, in <module>
    result = service.export('  {}'.format(service.title), 'File Geodatabase', parameters=None, wait='True') 
  File "/home/raphael/.local/lib/python3.8/site-packages/arcgis/gis/__init__.py", line 10855, in export
    export_item = Item(gis=self._gis, itemid=res["exportItemId"])
KeyError: 'exportItemId'

2 Answers 2

1

You're creating an anonymous connection to ArcGIS.com, then the code is attempting to generate a FileGDB. As you're anonymous, the FileGDB you're requesting has no place to go.

If you have an account in ArcGIS.com, I'd first try to login with that. However, even after that, you might not be able to export to a FileGDB; the content owner may have this ability blocked.

1
  • I do connect with my account i just left that part blank in the question
    – ziggy
    Oct 27, 2021 at 18:13
0

what I ended up doing is just manually grabbing the query links and using ogr2ogr to pull them into postgres

ogr2ogr -f PostgreSQL --config PG_USE_COPY YES  PG:"connection info" "https://services5.arcgis.com/gFh7gtZrHd449arT/ArcGIS/rest/services/greenez514_SW5_District_Layers/FeatureServer/7/query?where=objectid+is+not+null&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pgeojson" OGRGeoJSON -progress -overwrite -nln warren_county_schools -lco geometry_name=geom -t_srs EPSG:4326\
&&\
ogr2ogr -f PostgreSQL --config PG_USE_COPY YES  PG:"connection info" "https://services5.arcgis.com/gFh7gtZrHd449arT/arcgis/rest/services/greenez514_SW5_District_Layers/FeatureServer/8/query?where=objectid+is+not+null&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pgeojson" OGRGeoJSON -progress -overwrite -nln warren_county_daycares -lco geometry_name=geom -t_srs EPSG:4326\

etc...

i did mess around with the arcgis python API but the docs are surprisingly really bad for this type of stuff. It does seem possible to download it with python but I just gave up and spent 20 minutes getting the queries for ogr2ogr

from arcgis.gis import GIS
from arcgis.features import GeoAccessor, GeoSeriesAccessor
gis = GIS(None,'user', 'pass', verify_cert=False)
service = gis.content.get('f6325cf72860419b8f75bae4259344a5')
for a in service.layers:
    print(a)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.