1

I'm trying to convert a bunch of shapefiles into geoJSON and found what looks like an easy way to do it but I can't get the code working. It doesn't matter if I run the code in OSGeo4W or just via idle I get the same error. (I do have OSGeo4W added to the system path.) My code and error are below. Could I get some guidance on what might be causing this?

import gdaltools

layer = <myFilePath>

ogr = gdaltools.ogr2ogr()
ogr.set_encoding("UTF-8")
ogr.set_input(layer, srs="EPSG:4326")
ogr.set_output('layer.geojson')
ogr.execute()

And the error:

Traceback (most recent call last):
  File "C:\Users\JOC-001\Desktop\Python Scripts\Random\Folium\GeoJSON\Con2GeoJSON.py", line 9, in <module>
    ogr.execute()
  File "C:\Python27\ArcGIS10.2\lib\site-packages\gdaltools\ogr2ogrcmd.py", line 289, in execute
    return self._do_execute(args)
  File "C:\Python27\ArcGIS10.2\lib\site-packages\gdaltools\basetypes.py", line 90, in _do_execute
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1)
  File "C:\Python27\ArcGIS10.2\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Python27\ArcGIS10.2\lib\subprocess.py", line 948, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
  • WindowsError: [Error 2] The system cannot find the file specifiedis the error therefore ogr don't find layer – gene Jan 8 '17 at 19:04
  • Haha. Yeah I got that. But the file path is correct. I've verified it. I even ran the script from the same directory as the file and get the same error – Russel204 Jan 8 '17 at 19:11
  • Ok, look a pygdaltool: configuration – gene Jan 8 '17 at 19:29
  • Yep this is what I used to configure it. This Github repo is the reason i decided to try it. I should also add that I tried using ogr2ogr via command line and it worked. So I could get around this issue by using the OS module. BUT if you have any ideas where I messed up that is causing this problem I would appreciate your help! Thanks! – Russel204 Jan 8 '17 at 19:31
1

Pygdaltools use the subprocess module to execute directly the GDAL commands. The module must therefore know the exact path of the folder where they are (where are gdalinfo, ogrinfo, ...).

The configuration of the module lets do it:

import gdaltools
gdaltools.Wrapper.BASEPATH = "C/Program Files/Gdal/bin"

In this example, the command used by the module with subprocess are "C/Program Files/Gdal/bin/ogrinfo (ogrinfo.exe in Windows ?)", etc...

  • I followed your advice and was given this error: ERROR:root:ERROR 4: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files. ERROR 1: Failed to process SRS definition: EPSG:4326 – Russel204 Jan 8 '17 at 20:05
  • I added that VAR to the environment variables and still got the error. I'm going to reboot and see if that helps – Russel204 Jan 8 '17 at 20:07
  • Rebooting after adding the GDAL_DATA to environment variables has fixed it! I have marked your answer as correct. Thanks so much for your help! – Russel204 Jan 8 '17 at 20:21

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.