3

I have a fodler with 1500 ECW rasters, no spatial reference information defined. Can I use GDAL to batch define a projection for all 1500 in the folder?

2
  • for what operating system?
    – nickves
    Commented Jul 13, 2013 at 13:06
  • I'm using Windows 7
    – detroit_hc
    Commented Jul 13, 2013 at 13:11

2 Answers 2

4

ECW is ERDAS Compressed Wavelets (.ecw) type and support for it's not enabled by default (it needs the ECW SDK). There might be an option to install the necessary requirements via the OSGeo4W installer.

Check one of your files with gdalinfo, and if you get a valid output then, you can use the gdalwarp utility with -t_srs EPSG:XXXX and -te xmin ymin xmax ymax flags.

If you have installed gdal with the OSGeo4W installer, you should have the MSYS program which is a collection of GNU utilities such as bash and others.

Open it, cd to your folder and issue the following command:

for file in $(ls .ecw); do 
    gdalwarp -t_srs EPSG:XXXX -te xmin ymin xmax ymax $file $(basename $file .ecw).tif; 
done

The above command will create georeferenced geotiffs based on the inputs. BEfore batch processing all the files, try it on a test file first. The -te numbers are the extends of your raster in georeferenced coordinates, and EPSG is the CRS of your choice.

2
  • 1
    Hey Nickves, you can even remove the basename process and make use of parameter substitution. $(basename $file .ecw).tif -> ${file%ecw}tif - it's not a major change but bash can do a lot of the heavy lifting. The loop might not even need to call ls too. You can replace $(ls .ecw) -> *.ecw
    – SaultDon
    Commented Jul 16, 2013 at 15:46
  • Ooh nice, I'll give it a try next time I need it!
    – nickves
    Commented Jul 16, 2013 at 15:52
-1

You might find using the ERDAS APOLLO Essentials Utilities to be easier to update the headers.

  1. Download and install the following (windows only) http://geospatial.intergraph.com/service/support/fixes_enhancements/details/ERDAS_APOLLO_Essentials_Utilities_2013_v13_01.aspx
  2. Open cmd line, CD to C:\Program Files\Intergraph\APOLLO Essentials Utilities 2013\bin
  3. Use the ECWHeaderEditorCLI.exe utility to define coordinate information (for example using a batch file)

Usage: ECWHeaderEditorCLI.exe file [-proj PROJECTION] [-datum DATUM] [-originx O RIGINX] [-originy ORIGINY] [-cellx CELLX] [-celly CELLY] [-updateers] [-updateecwwithuncompressedindextable] [-updatewithincorrectdatum projectionpair ] [-updatewithinvalidcoordspace]

for example,

ECWHeaderEditorCLI.exe file1.ecw -proj EPSG:4326 -datum EPSG:4326

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.