7

I have a shapefile of world countries, with longitude between -180° and 180°. How can I change the shapefile (eg. with ogr2ogr) for having longitude between 0 and 360°.

Following OSGEO/Trac explanation about GenParms, I tried this without success (the result is still in -180 - 180:

ogr2ogr -wrapdateline -t_srs '+proj=latlong +datum=WGS84 +lon_wrap=-180 +over' /data/tmp/new_algo/world_new.shp /data/tmp/new_algo/world.shp

I need to have the new longitude defined as:

if Lon < 0: new_Lon = 360 + Lon else: new_Lon = Lon

Of course, the process must take care of the date line.

3
  • Do you mean if Lon < 0: new_Lon = 360 + Lon else: new_Lon = Lon? Commented Dec 4, 2013 at 16:23
  • Yes, that's what I need (sorry for my typo, I've edited it now). I saw your answer below, the problem is that everything is shifted, including the parts in 0-180 that should not move. Commented Jan 7, 2014 at 9:07
  • I've updated my answer in order to consider your last comment. Hope this helps. Commented Jan 7, 2014 at 9:42

2 Answers 2

6

Using GDAL >= 1.10.0 compiled with SQLite and SpatiaLite:

ogr2ogr world_shifted.shp world.shp -dialect sqlite -sql "SELECT ShiftCoords(geometry,180,0) FROM world"

or:

ogr2ogr -s_srs EPSG:4326 -t_srs "+proj=longlat +ellps=WGS84 +pm=-180 +datum=WGS84 +no_defs" world_shifted.shp world.shp

Both commands produce a longitude offset of 180°, i.e. a prime meridian of -180° is considered. In fact:

>ogrinfo world_shifted.shp world_shifted | grep Extent
Extent: (0.000000, -90.000000) - (360.000000, 83.623596)

The difference between the two commands is that with a longitude offset (2nd try) data are simply reprojected using -180° as prime meridian, while shifting the coordinates geometries (1st try) are altered, even if the result is apparently the same.

EDIT
If there are parts in 0-180 that should not move, it's possible to adapt this working solution: https://gis.stackexchange.com/a/73164/22405

Clip the two parts:

ogr2ogr world_part1.shp world.shp -clipsrc -180 -90 0 90
ogr2ogr world_part2.shp world.shp -clipsrc 0 -90 180 90

Shift only the first part:

ogr2ogr world_part1_shifted.shp world_part1.shp -dialect sqlite -sql "SELECT ShiftCoords(geometry,360,0), CNTRY_NAME FROM world_part1"

Then, merge the second part and the first shifted:

ogr2ogr world_0_360_raw.shp world_part2.shp
ogr2ogr -update -append world_0_360_raw.shp world_part1_shifted.shp -nln world_0_360_raw

Finally, dissolve countries boundaries of world_0_360_raw.shp obtaining world_0_360.shp by country names. For instance:

ogr2ogr world_0_360.shp world_0_360_raw.shp -dialect sqlite -sql "SELECT ST_Union(Geometry), CNTRY_NAME FROM world_0_360_raw GROUP BY CNTRY_NAME"
4
  • Sorry, it is not what I meant: the command you gave shifts the values, while I want to have another longitude mapping domain: [0 360] instead of [-180, 180], which means that the map will be centered on 180° (in the pacific) instead of 0° (Greenwhich). So I guess the operation should include some modulo operator? Commented Dec 4, 2013 at 15:22
  • In fact, a longitude offset (2nd try) produce a mapping domain of [0 360] and data are simply reprojected using -180° as prime meridian. Instead, shifting the coordinates geometries (1st try) are altered, even if the result is apparently the same. Commented Dec 4, 2013 at 16:33
  • Yes, simple but perfectly working approach. Thanks! Now, I only need to figure out how to get ride of the vertical line (border between the two dissolved polygons) that remains after the dissolve operation. Commented Jan 7, 2014 at 10:15
  • Where? The last ogr2ogr command works fine for me. There are only some multipolygons which fall near 0° and 360°, after the dissolve operation. Commented Jan 7, 2014 at 10:23
1

I'm afraid the +lon_wrap parameter is not implemented in ogr2ogr.

See http://comments.gmane.org/gmane.comp.gis.proj-4.devel/5131

http://r-sig-geo.2731867.n2.nabble.com/Proper-PROJ-settings-for-lat-long-td5592484.html

And if Frank W. says it is not you have to live with that ;-)

If you only want a map centered on the pacific, try a map projection with 180°E as center meridian:

QGIS display world country shape files centered on pacific ocean using Robinson, Miller Cylindrical or other projection

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.