3

I'm trying to reproject, move from tab to shp and rename all the .tab contained in a folder tree using ogr2ogr.

I'm working with Windows 7, QGIS 1.8 installed with advanced OsGeo4w and gdal 1.9.2. I have no experience in batch.

Here's the code :

for /R %%f IN ('D:\3.BATCH\FAUNE\*.tab') do C:\Users\Samy\Desktop\SIGMA\15.webmapping\ms4w\tools\gdal-ogr\ogr2ogr.exe -s_srs EPSG:3727 -t_srs EPSG:2975 %%f "ESRI Shapefile" %%f_2975.shp %%f

By calling this .bat into the cmd line, nothing append. When I simplify the code, I have in the best case "Unable to open" as @Nik posted in the 3rd resource below.

I wrote this code with the following questions:

  1. Using ogr2ogr to convert all shapefiles in directory?

  2. Is there any way to reproject multiple layers in QGIS?

  3. How to reproject shapefile using ogr2ogr

According to resource 1, I translate the -f "MapInfo File" "%~dpnf.tab" "%f" into %%f "ESRI Shapefile" %%f_2975.shp %%f because as it is shaped, I can't use dpnf.

According to resource 2, I wrote -s_srs EPSG:3727 -t_srs EPSG:2975 to reproject.

Finally, I checked that the "Hide extensions for known file types" was off, according to resource 3.

I don't know what to do now. There seem to be so many different ways to write this one line of code.

1 Answer 1

4

There are a few %%f too much in your command line. This one worked for me (with another conversion target):

for /R %%F IN ('D:\3.BATCH\FAUNE\*.tab') do C:\Users\Samy\Desktop\SIGMA\15.webmapping\ms4w\tools\gdal-ogr\ogr2ogr.exe -s_srs EPSG:3727 -t_srs EPSG:2975 -f "ESRI Shapefile" %%~dpnF_2975.shp %%F

The main obstacle is that %%F already contains the file extension, so you have to skip that with ~dpnF_2975.shp.

Note that f and F are considered different by the Operating System.

You skipped the ~dpnf, but that is the essential part of clipping the file name to the desired part without extension. You can replace dp with full drive and path name.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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