1

I try to make ogr2ogr work in Python the way suggested by Elevine's answer elsewhere, but I'm facing bugs. Most notable error is that while I try to reproject shapefiles, I get the following error:

Unable to open datasource `lesy_w.shp' with the following drivers.

A list of formats follow, including "ESRI SHapefile". My command looks like this:

ogr2ogr.main(["", "-f","ESRI Shapefile", "-s_srs","epsg:4326", "-t_srs","epsg:32633", "lesy_u.shp","lesy_w.shp"])

The corresponding ogr2ogr command (ogr2ogr -f ESRI Shapefile -t_srs epsg:32633 lesy_u.shp lesy_w.shp) works well in the command line. It's a simple line geometry, no "geometry collection". The input shapefile (lesy_w.shp) is loaded as a QGIS layer normally. I tested this with other layers and the problem is still there.

I get the same error also while trying other operations, like converting to KML without reprojection. The same when I try to convert from kml to shapefile.

Is filing this as a bug in ogr2ogr.main() my only option, or is there any solution?

  • Is the typo in -s_srs","eps:4326" only in your question or in the code as well? – user30184 Aug 11 '15 at 7:29
  • @user30184: in my code as well. I've corrected it, but the error remains. – Pavel V. Aug 11 '15 at 7:31
  • The error can also mean that "lesy_w.shp" can't be found because it is not in the default path. – user30184 Aug 11 '15 at 7:35
1

Using python code, you can not be sure in which folder the ogr command will be executed. In most cases, your data files will not be in a path included by the PATH variable, or the path where ogr2ogr.exe is located.

Therefore it is always safe to add the full pathnames to source and destination files (for the python command as well as on the command line).

|improve this answer|||||

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