2

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'])
asked Jun 22, 2016 at 3:02
2
  • I confirmed his url works with i=0 and i=2000. Also I'd never seen that multi-line string syntax before, but it checks out.. For sanity you might try invoking ogr2ogr command line programmatically, like this: os.system(ogr2ogr_terminal_instruction) My assumption is something must be wrong with how your submitting your arguments to ogr2ogr.main() Commented Jun 22, 2016 at 14:33
  • Thanks for the comment, yes I can certainly do that, though I wish I could get this working. Is it pretty much equivalent to use os.system or subprocess.call? Commented Jun 22, 2016 at 20:16

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.