I found this helpful post that got me started using ogr2ogr in python: Using ogr2ogr to convert GML to shapefile in Python? as well as this one: Converting ArcGIS Server JSON to GeoJSON? I am trying to take JSON from arcgis service query results and convert to geojson. I am querying OBJECTIDs in increments of 1,000 as the query results limit is set to 1,000. I tested this and it works in command line, but when I run the script, I get an error saying unable to open data source. Can someone help?
import os
import ogr2ogr
def main():
for i in range(0,83000,1000):
url = ('https://gisrevprxy.seattle.gov/ArcGIS/rest/services/SDOT_EXT/sdot_parking/MapServer/5/query?'
'text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&'
'relationParam=&objectIds=&where=OBJECTID%3E+'+str(i)+'&time=&returnCountOnly=false&returnIdsOnly='
'false&returnGeometry=true&maxAllowableOffset=&outSR=&outFields=OBJECTID%2CShape%2CSEGKEY%'
'2CELMNTKEY%2CDISTANCE%2CWIDTH%2CSIGNTYPE%2CSTANDARDTEXT%2CCATEGORY&f=pjson')
outfile = os.path.join('/Users/kirsten_lawrence/Documents','recs_'+str(i)+'up.json')
# note: main is expecting sys.argv, where the first argument is the script name
# so, the argument indices in the array need to be offset by 1
print 'creating geojson starting at record',i
ogr2ogr.main(['','-f', 'GeoJSON', outfile, url, 'OGRGeoJSON'])
os.system(ogr2ogr_terminal_instruction)
My assumption is something must be wrong with how your submitting your arguments toogr2ogr.main()