# [gdal-dev] Re: can ogr2ogr split polygons that cross 180 degree longitude

Even Rouault even.rouault at mines-paris.org
Mon Sep 28 04:16:26 EDT 2009

```Selon Hermann Peifer <peifer at gmx.eu>:

I think this should be prefectly doable with some code/script just using OGR
API.

Here's a possible algorithm :

1) Create a new empty WGS84 shapefile
1) Loop over features in the source shapefile (the one after reprojection to
WGS84)
2a) If the polygon has points with longitudes both near 180° and near -180°,
create a duplicate temporary polygon and add 360° to the negative longitudes.
Compute the interescection with Geometry.Intersect (you need GEOS support) of
that polygon with POLYGON((0 90,180 90,180 -90,0 -90,0 90)) and with
POLYGON((180 90,360 90,360 -90,180 -90,180 90)). For the second intersection,
substract 360° to the longitudes in order to get again longitudes in the
[-180,180] range. Finally, write 2 new features into the output shapefile, or
better, just one with the geometry being a multipolygon with the 2 parts.
2b) Otherwise, just copy the original feature into the output shapefile

Best regards,
Even

> Eric,
>
> I can't help much apart from confirming that the same happened to me
> when trying to reproject Russia from LAEA to WGS84.
>
> My "solution" was to ask a colleague, who is using ESRI products to do
> me a favour... :-(
>
> Hermann
>
>
> Eric Muller wrote:
> > I am trying to reproject  shapefiles that represent Russia (from
> > from the original:
> >
> >     The map is Albers equal-area projection Clarke spheroid of1866 with
> >     the first standard parallel 46 00 0.000, the second standard
> >     parallel 73 00 0.000, the central meridian 84 00 0.000. The latitude
> >     of the projection's origin is 60 00 0.000.  Units -- meters.
> >
> > to lat/long WGS84. I use the following command:
> >
> > ogr2ogr \
> >     -s_srs '+proj=aea +ellps=clrk66 +lat_1=46.0 +lat_2=73.0 +lat_0=60.0
> > +lon_0=84.0 +units=m +no_defs' \
> >     -t_srs '+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs' \
> >     rs_polbnda_\${f}.shp rus\${f}.shp
> >
> > I would like polygons that cross the 180 degree longitude to be split.
> > It there a way to ask ogr2ogr to do that? What is the recommended way to
> > do it, if not?
> >
> > Thanks,
> > Eric.
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>

```