Tuesday 19 April 2016

ogr - Call FWTools (ogr2ogr) from ArcGIS python script


In ArcGIS, I want to use a Python script (and a standard ArcGIS script tool UI) to call functionality from FWTools.


How would I make the call to FWTools? I tried using os.system(C:\WINDOWS\system32\cmd.exe /K "C:\Program Files\FWTools2.4.7\setfw.bat") which is what the windows shortcut calls, but that is not it. It seems I am probably missing something rather simple, but I can't figure out how to make the right call through python to get FWTools & ogr2ogr operating on the string I pass.


My UI looks like this:


enter image description here


and the pseudo-code behind it is something like:



'ogr2ogr -f "' + outformat + '" "' + outfile + '" "' + infile + '" ' + ogrvars

Answer



It turns out it was just a silly mistake on my part and forgetting that paths in Python need to be either "\" or "/". The code itself was very simple:


'"C:\\WINDOWS\\system32\\cmd.exe /C" "C:\\Program Files\\FWTools2.4.7\\bin\\ogr2ogr.exe" ' + ogrstring

I have posted the toolbox and python code at:


http://resources.arcgis.com/Resources2010/gallery/file/geoprocessing/details?entryID=068D81A7-1422-2418-A092-A96C07DB6E25


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...