Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ? –  philanthropist Dec 11 '13 at 12:46
    
@Anil None yet. Please let me know if you find one. –  CaptDragon Dec 11 '13 at 15:15
add comment

5 Answers

up vote 3 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 at 21:13
add comment

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
add comment

Workround: Example

var mapserv = new OpenLayers.Layer.MapServer( "OpenLayers Basic",
                "http://vmap0.tiles.osgeo.org/wms/vmap0",
                {layers: 'basic'},
                {wrapDateLine: true} );

http://openlayers.org/dev/examples/wrapDateLine.html

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
add comment

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;
  }
}

Update:

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
add comment

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. http://trac.osgeo.org/openlayers/ticket/2754 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
add comment

Your Answer

 
discard

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.