[Gdal-dev] Transforming geographic coords from 0_360 to -180_180?

Frank Warmerdam warmerdam at pobox.com
Thu Mar 25 12:53:43 EST 2004


IMD Listuser wrote:
> Greesting again list
> 
> I was able to use gdal_translate to create a GeoTIFF once I recompiled
> gdal with the support for netCDF and the recently updated nmake.opt and
> makefile(s). Thanks to Norman and Frank ;)

Charlie,

Cool, I'm glad the netcdf route worked.

> Now I have follow-on question(s)
> 
> -Is it possible to control the color depth of the output geotiff using
> gdal_translate. I am not able to open the file in photoshop. The error
> it throws is something like unsupported color depth.

The gdal_translate utility has a -ot switch which you can use to set
the pixel type of the output file.  For example the following command
would convert a file to 8bit unsigned. However, it does it by truncating
all values outside the range 0-255 (les than 0 to 0, greater than 255 to 255).

gdal_translate -ot Byte in.tif out.tif

To actually scale the data, you can use the -scale switch.  There are
various configurations, but often the default (auto scaling) is fine.

   gdal_translate -scale -ot Byte in.tif out.tif

See the gdal_translate usage message for a full list of output data types.

> -Can gdal_translate produce a world file along with the geotiff?

If you read the GeoTIFF format driver docs, you will see there is creation
option for this.  You could use it like this:

   gdal_translate -co TFW=YES in.tif out.tif

The resulting file would have an out.tfw file.

> -The original bounds of the netCDF data are expressed in decimal degrees
> from 0 to 360. What is the best way for me to convert to standard
> hemispheric decimal degrees (-180 to 0 then 0 to 180)?

This is a bit tricky because you effectively need to swap the sides of the
image.  You could split the file into two hemispheres like this:

   gdal_translate -srcwin 0 0 5400 6336 in.tif    east.tif
   gdal_translate -of PAux -srcwin 5400 0 5400 6336 in.tif west.raw

Now, I made the west side into a PAux file so I could easily edit the
georeferencing.  Just edit west.aux and change the map x coordinates to
look like this:

AuxilaryTarget: west.raw
RawDefinition: 5400 6336 1
ChanDefinition-1: 16S 0 2 10800 Swapped
UpLeftX: -180.000000000000
UpLeftY: 72.006000000000
LoRightX: 0.000000000000
LoRightY: -72.006000000000

Now, if you have a full GDAL system, with python, you could use the
gdal_merge.py script to merge the east and west side into one file again:


   python ~/gdal/pymod/gdal_merge.py -o merged.tif east.tif west.raw

Of course there are other ways of accomplishing the same thing, but hopefully
this is helpful.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list