Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using OpenLayers, I added a WFS layer (on GeoServer) with a filter that returns all features (black) that intersect my polygon (yellow) placed over some Latin American countries within certain dates.

enter image description here

However, the feature that crosses horizontally across the map does NOT actually intersect my polygon. This feature is somewhere in the pacific ocean between Hawaii and Fiji and NOT in Latin America. The problem is that instead of crossing the International Date Line it is being rendered on the map by wrapping around the whole world.

The problamatic feature is defined:

POLYGON((-179.700417 14.202717,-178.687422 13.992875,179.024138 8.24716,-179.98241 8.035567,-179.700417 14.202717))

I have many of problematic date line features like this but have narrowed it down to this one for this example. I can't just ignore it in my application because i have many of them.

I've tried using "wrapDateLine: true" in base layer and WFS layer with same results.

Not sure if this would be a GeoServer problem or an OpenLayer problem.

Does anyone know a solution to my international date line problem?

share|improve this question
I don't know why software has such a problem with this, the world is flat, right?! – DavidF Mar 10 '11 at 18:03
Maybe there should be a direction parameter. – CaptDragon Mar 10 '11 at 18:08
@CaptDragon Any solution to this Problem ? – Anil Dec 11 '13 at 12:46
@Anil None yet. Please let me know if you find one. – CaptDragon Dec 11 '13 at 15:15
up vote 4 down vote accepted

Unfortunately this is a known problem. The issue is that geometries that cross the date line like this are ambiguous. The OL and GeoServer renderers have no easy way of knowing that the intention is to go the "short" way around the world so they just interpret for instance 170 to -170 the "regular" way and go the long way around the world.

Unfortunately there is no good solution for this except to split up your geometries that lie across the dateline.

share|improve this answer
Thanks +1, i agree but i can't split my geometries. Let's see if anyone else has any other ideas. – CaptDragon Mar 10 '11 at 18:03
I figured out a way to split them nicely on OpenLayers. – CaptDragon Jan 21 '14 at 21:13

Reproject your map to use a projection which is split at the Greenwich meridian (or elsewhere) so that the polygons you are interested in don't cross the discontinuity in your map.

share|improve this answer
the polygons cover the world pretty well there will always be polygons that will cross some line. Though, do you know of any projections that are not split like this? – CaptDragon Mar 10 '11 at 18:53
All projections must split the world somewhere, it is implicit in the maths (peel an orange if you don't believe me :-)). All you can do is pick the best projection for your task. – iant Mar 10 '11 at 19:09
yeah you're right. I'll leave this open a few days and see if any other ideas come up. Thanks for your suggestion.:-) – CaptDragon Mar 10 '11 at 19:51

Workround: Example

var mapserv = new OpenLayers.Layer.MapServer( "OpenLayers Basic",
                {layers: 'basic'},
                {wrapDateLine: true} );

share|improve this answer
I'm using WFS the link you posted says: "You can do it with a 'Layer.WMS' or a 'Layer.MapServer' layer" – CaptDragon Mar 10 '11 at 18:06
If both are supported and you don't have a specific need for Layer.MapServer, go with Layer.WMS (which could still be served from MapServer). – DavidF Mar 10 '11 at 18:50
@DavidF: Thanks, but I need to use the vector capabilities of WFS. – CaptDragon Mar 10 '11 at 19:53

Two years later, I kept having this issue with features on a vector layer. I found this file containing a snippet of code that shows how to flip an endpoint if it crossed the dateline:

if(Math.abs(startPoint.x-endPoint.x) > 180) {
  if(startPoint.x < endPoint.x) {
    endPoint.x -= 360;
  } else {
    endPoint.x += 360;


Actually the above did not work for more than one revolution around the world. I ended up doing THIS.

enter image description here

share|improve this answer

I had few issues with dateline and managed to fix all of them. You could try following.

  1. Update the GeoServer layer bounding box values manually to cover your polygon without breaking and see whether it solves the issue.

  2. One of the fix i have done in Openlayers is missing tiles when passing dateline from +ve longitude to -ve. Not sure whether it applicable for WFS. You could get the latest openlayers development version and try.

share|improve this answer
Thanks, i'll give this a shot. – CaptDragon Mar 29 '11 at 13:34

I've come up with a solution for this in my own projects that may or may not work for you. I know for a fact that it works with LineStrings but I'm not sure about other geometry types.

OpenLayers.Geometry.prototype.crossesDateLine = function() {
    var lastX = this.components[0];
    for (var i=0; i < this.components.length; i++) {
        if (Math.abs(this.components[i].x - lastX) > 180) return i;
        lastX = this.components[i].x;
    return false;
OpenLayers.Geometry.prototype.dateLineFix = function() {
    var linestrings = [];
    if (this.crossesDateLine()) {
        var string1 = [];
        for (var i = 0; i < this.crossesDateLine(); i++)
        var ls1 = new OpenLayers.Geometry.LineString(string1);
        var string2 = [];
        for (var i = this.crossesDateLine(); i < this.components.length; i++)
        var ls2 = new OpenLayers.Geometry.LineString(string2);

        if (!ls1.crossesDateLine()) {
        } else {
            var split = ls1.dateLineFix();
            for (var i = 0; i < split.components.length; i++)
        if (!ls2.crossesDateLine()) {
        } else {
            var split = ls2.dateLineFix();
            for (var i = 0; i < split.components.length; i++)
    } else {
    return new OpenLayers.Geometry.MultiLineString(linestrings);

The dateLineFix function recursively traverses the given LineString for any segments that cross the date line. It then cuts them in two at the dateline and returns all of the resulting segments as a MultiLineString.

It worked perfectly for my purpose (drawing a polar lat-lon grid).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.