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 Answers
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.
-
1Hey 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 callls
too. You can replace$(ls .ecw)
->*.ecw
– SaultDonCommented Jul 16, 2013 at 15:46 -
You might find using the ERDAS APOLLO Essentials Utilities to be easier to update the headers.
- Download and install the following (windows only) http://geospatial.intergraph.com/service/support/fixes_enhancements/details/ERDAS_APOLLO_Essentials_Utilities_2013_v13_01.aspx
- Open cmd line, CD to C:\Program Files\Intergraph\APOLLO Essentials Utilities 2013\bin
- 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