[Gdal-dev] Tool to convert shapefile from [-180, 180] to [0, 360] range

Frank Warmerdam warmerdam at pobox.com
Fri Jun 16 15:26:07 EDT 2006


Daniel Morissette wrote:
> Is anyone aware of a tool or script that would convert the longitude of 
> coordinates in a shapefile from [-180,180] to [0,360]? The tool could be 
> based on OGR or any other open source package.
> 
> Just checking before writing something from scratch and reinventing the 
> wheel.

Daniel,

I imagine you have what you need working now, and I see there was an
extensive thread on this issue.  I just wanted to add that in recent
works I've done some work on the OGRCoordinateTransformation object
related to supporting a "wrapping center" for geographic coordinate
systems.

It is now possible to define a wrapping center longitude, and the
OGRCoordinateTransformation object will take care of forcing longitudes
into the range center-180 to center+180.  This can be accomplished using
the CENTER_LONG configuration option like this:

   gdalwarp --config CENTER_LONG 180 openev/utm.tif ll.tif -t_srs WGS84

In the above case, the output lat/long file will use the range 0 to 360
instead of the default -180 to 180.

I also have an extension to WKT for setting this.  I believe you add
an entry like EXTENSION["CENTER_LONG",180] as a child of the GEOGCS node.
I would have mentioned this whole issue here sooner, except that I just
know that Martin Daly will now rightly jump all over me for corrupting
the standard WKT format.  I must say, I now regret not having advocated
on behalf of a vendor specific extension mechanism in the past. :-)

The gdalwarp utility now has some built-in smarts to apply a CENTER_LONG
to the source coordinate system center in the middle of the dataset.  The
original problem that motivated me to do something had to do with reprojection
away from lat/long and the projected coordinates for sampling not reprojecting
back onto the source dataset in the proper range.

I haven't written up an RFC on all this as I consider it quite experimental
though I must confess I have committed it in CVS.

In your case, I think it should be possible to run ogr2ogr like:

   ogr2ogr out.shp in.shp --config CENTER_LONG 180 -t_srs WGS84 -t_srs WGS84

though I haven't tried it to see if there are issues.  This certainly won't
take care of splitting a geometry that crosses the meridian as ought to be
done when transforming.  For points this won't matter, but it will for
line or polygon files.

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    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list