2

I'm trying to use GDAL polygonize to run a batch convert but I cannot for the life of my figure out a way to get it to read a text file as input that contains all of the commands.

Do you know the correct command to run this conversion in one step so I don't have to do it many times over?

Here's an example of a single line of my input txt file:

gdal_polygonize X:\Source-Imagery\Satellite\WaterMask\Collection_5\2000\ALL\MOD44W_Water_2000_ML1920.tif\MOD44W_Water_2000_ML1920.tif -f "ESRI Shapefile" X:\Source-Imagery\Satellite\WaterMask\Collection_5\2000\ALL\MOD44W_Water_2000_ML1920.tif\MOD44W_Water_2000_ML1920.shp 

The txt file contains 176 lines to convert.

2

It should work this way:

  1. Start the OSGEO4W shell
  2. Change the folder with cd to the folder where your batch file is, or copy the batch into the folder where the shell lands
  3. Run the batch inside the shell by manually typing filename.bat

You don't need to care for PATH variables, this is done when starting the OSGEO4W shell.

1

On Windows:

  1. Save text file as a "batch file" by changing the file extension from ".txt" to ".bat"
  2. double-click that file and away you go.
4
  • I guess it's not that easy. I get the error: "gdal_polygonize is not recognized as an internal or external compatible program or batch file". Any other suggestions? There must be a way to force Windows to use OSGeo4W, right? Is there something I should change on my commands?
    – Matt G
    Aug 3 '15 at 16:21
  • is OSGeo4W installed in C:\OSGeo4W\bin? You could try adding that to your PATH. Though check here for possible side effects: trac.osgeo.org/osgeo4w/ticket/121. Prepending the full path to gdal_polygonize in your batch file might also work C:\OSGEO4W\bin\gdal_polygonize ...
    – toms
    Aug 3 '15 at 16:41
  • Thanks for the tips but nothing has succeeded thus far. My OSGeo4W (GDAL Polygonize) is location here: 'C:\OSGeo4W64\bin'. I've tried adding the paths but I still get errors and nothing is converted. I've tried: 'C:\OSGeo4W64\bin\gdal_polygonize X:\Source-Imagery\Satellite\....tif\MOD44W_Water_2000_KJ3334.tif -f "ESRI Shapefile" X:\Source-Imagery\Satellite\....tif\MOD44W_Water_2000_KJ3334.shp' I've also tried adding the .py and .bat
    – Matt G
    Aug 3 '15 at 21:20
  • Did you try adding C:\OSGeo4W\bin to your windows PATH? Best reference I could find quickly: java.com/en/download/help/path.xml This is java specific, but the general idea is the same
    – toms
    Aug 3 '15 at 22:36
1

I think this might solve your problem:

To set up the o4w environment, add this to the start of your bat file:

Call C:\OSGeo4W\bin\o4w_env.bat

Run all the lines from the text file there.

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.