Jump to content

 
Photo

Batch Project Raster Tool

- - - - -

  • Please log in to reply
19 replies to this topic

#16
Hans van der Maarel

Hans van der Maarel

    CartoTalk Editor-in-Chief

  • Admin
  • PipPipPipPipPipPipPip
  • 3,838 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Cartography, GIS, history, popular science, music.
  • Netherlands

The way I would do it would be without a batch-file, just directly in the "dos box" console (cmd.exe):

dir /B *.tif | gdalwarp -s_srs EPSG:4326 -t_srs EPSG:27700 %%f c:\out\%%f


This falls over with an error message:

ERROR 4: `%%f' does not exist in the file system, and is not recognised as a supported dataset name.

Regards, N.


I don't think Hugo's suggestion is going to work. The first part simply creates a list of all tiff files in a directory, but there's not telling the second part what to do with them.
Hans van der Maarel - Cartotalk Editor
Red Geographics
Email: hans@redgeographics.com / Twitter: @redgeographics

#17
Nick H

Nick H

    Legendary Contributor

  • Validated Member
  • PipPipPipPipPip
  • 307 posts
  • Gender:Male
  • Location:Caversham, Reading, England.
  • United Kingdom

Hope you don't mind Hans, I've just added a few instructions to your batch file. So, copy the code below, paste it into a plain text editor (Notepad will do) and save it as (say) 'warp.bat'. Then follow the directions in the file.

@echo off

call "C:\Program Files\FWTools2.4.6\setfw"

for %%f in (*.tif) do gdalwarp -s_srs EPSG:4326 -t_srs EPSG:27700 %%f warped\%%f

REM

REM	 ***READ ALL OF THESE NOTES BEFORE DOING ANYTHING***

REM

REM (1) Install FWtools from http://fwtools.maptools.org/. The current version for Windows will

REM	 install by default in C:\Program Files\FWTools2.4.6. If it is installed in a different

REM	 directory the second line of this file will need to be edited to reflect this fact.

REM  

REM (2) Place this batch file in the directory containing the GeoTIFFs to be processed.

REM

REM (3) To run the batch file open a command line window in the directory containing this batch file

REM	 and the TIFFs to be processed. Assuming you have called this batch file 'warp.bat', at the

REM	 command prompt type 'warp' and press return (or you can just click on the 'warp.bat' icon).  

REM

REM (4) In line 2 of this file the output directory (where the processed TIFFs will be placed) is

REM	 called 'warped'. This is a sub-directory of the directory containing this batch file and the

REM	 GeoTIFFs for processing and it must be created before the batch file is run.

REM

REM (5) Edit the source and target ESPG codes in Line 3, as needed. EPSG codes may be obtained from

REM	 http://spatialreference.org/. In Line 3 the first EPSG code is for the source projection and

REM	 the second is for the target projection.

Regards, N.
Caversham, Reading, England.

#18
frax

frax

    Hall of Fame

  • Associate Admin
  • PipPipPipPipPipPipPip
  • 2,299 posts
  • Gender:Male
  • Location:Stockholm, Sweden
  • Interests:music, hiking, friends, nature, photography, traveling. and maps!
  • Sweden

Yup sorry about my error, one needs to make sure that the list ends up in the right places, and you need a program like xargs.exe for that, I have that from some old aix compability toolkit I downloaded at some point - then this should work:
dir /B *.tif | xargs gdalwarp -s_srs EPSG:4326 -t_srs EPSG:27700 {} c:\out\{}

Hugo Ahlenius
Nordpil - custom maps and GIS
http://nordpil.com/
Twitter

#19
frax

frax

    Hall of Fame

  • Associate Admin
  • PipPipPipPipPipPipPip
  • 2,299 posts
  • Gender:Male
  • Location:Stockholm, Sweden
  • Interests:music, hiking, friends, nature, photography, traveling. and maps!
  • Sweden

The toolkit I am referring to is AINTX, and you can find a link to it here: http://www.pcreview....ead-1503674.php
Hugo Ahlenius
Nordpil - custom maps and GIS
http://nordpil.com/
Twitter

#20
angelicafloyd

angelicafloyd

    Newbie

  • New Member
  • Pip
  • 1 posts
  • United States

A simple stand alone python script I have used to batch project raster files is:

 

import arcpy

arcpy.env.workspace = r"file_path"

rasterList = arcpy.ListRasters()

 

for raster in rasterList:

       outFile = r"out_file_path"

       outRaster = outFile + "\projection_"+raster

       outCS = r"C:\Program Files\ArcGIS\Desktop10.1\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"

       arcpy.ProjectRaster_management(raster, outRaster, outCS, "NEAREST", "#", "NAD_1983_To_WGS_1984_5", "#")






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

-->