Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
pause

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 ressource below.

I wrote this code with the following questions:

  1. ogr2ogr convert all shapefiles in a 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 shape, 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 ressource 3.

I don't know what to do now. There seems to be so many different ways to write this one line of code that I'm kind of disappointed.

Please help !

Samy

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

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 as 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.

share|improve this answer
    
Thank you very much, it works good ! –  Samy-DT Jul 3 '13 at 10:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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