I have a Python script that batch converts GPX files stored on an older Garmin unit to ESRI shapefiles. This script use an ogr2ogr command line argument passed from Python using subprocess.call()
to do the conversions. This all works very nicely on my Linux computer that I typically use for script development. I have full permissions on this computer.
Now I am converting the script to a Windows specific computer to which I do not have administrative rights. Furthermore, my Python environment is behind a walled-garden using ArcGIS Pro 2.7. When my script gets to the ogr2ogr conversion and subprocess.call()
I get an error message 'ogr2ogr' is not recognized as an internal or external command, operable program or batch file.
A previous post referring to Windows 7 stated that one should either set Environment Path Variables (which I cannot do since I do not have admin rights or run this command line statement "set path=%path%;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\osgeo\"
. As a test of all this I can run "set path" stuff without error in a Windows Power Shell but when I use the power shell to run ogr2ogr -f " Shapefile" Waypoint.shp Waypoints_01-OCT-19.gpx
in the directory with the GPX I get the error below.
`ogr2ogr : The term 'ogr2ogr' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ogr2ogr -f "ESRI Shapefile" Waypoint.shp Waypoints_01-OCT-19.gpx
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (ogr2ogr:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException`
How do I get my ogr2ogr command to run using Python and Windows 10?
1 Answer 1
The ArcGIS Pro python environment doesn't include the GDAL/OGR commandline utilities, just the python bindings.
You can use gdal.VectorTranslate
to do the same thing as ogr2ogr
.
Explore related questions
See similar questions with these tags.
gdal.VectorTranslate
I think you mean, notgdal.Translate
env
argument where you can pass a dictionary of variables so you don't need to mess with the system. Runset
from the osgeo shell to see what you might need to include there. You can also use the full path to the executable so it doesn't need to be discoverable via the system path, but depending on what you're doing GDAL might need some of those extra variables (PROJ_LIB
, etc.)