confusion about polygon definitions

Frank Warmerdam warmerdam at POBOX.COM
Fri Nov 12 17:04:27 EST 2004


Joseph Bussell wrote:
> How does one differentiate the polygon:
>
>    P1:  (  10,   179 )  (  -10,   179 )  (  -10,  -179 ) ( 10,  -179 ),
>    interior point at ( 1,  179.5 )
>
> from
>
>    P2:  (  10,   179 )  (  -10,   179 )  (  -10,  -179 ) ( 10,  -179 ),
>    interior point at ( 1, 100 )
>
> P1 is a small square at the international dateline.
> P2 is the large strip that wraps around the globe.
>
> My goal is to display both as unique.  I have several polygons which
> straddle the dateline and are not filling correctly.  I note however
> that the Asia polygon in my world shapefile crosses the dateline just
> fine.  Siberia appears correctly divided as one would expect.  Is there
> a point order such as a couter-clockwise point addition?

Joe,

A variety of factors may come into play with mapping across the anti-meridian.
I would encourage you to review, and update the Wiki WorldMappingIssues topic
as you learn more:

   http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?WorldMappingIssues

There has been a bunch of work to try and handle polygons that cross the
anti-meridian gracefully.  I wrote the following descriptive text in
mapproject.c about it when I worked on this area.  It may clear up some points
for you.


/*

Frank Warmerdam, Nov, 2001.

See Also:

http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=15

Proposal:

Modify msProjectLine() so that it "dateline wraps" objects when necessary
in order to preserve their shape when reprojecting to lat/long.  This
will be accomplished by:

1) As each vertex is reprojected, compare the X distance between that
    vertex and the previous vertex.  If it is less than 180 then proceed to
    the next vertex without any special logic, otherwise:

2) Reproject the center point of the line segment from the last vertex to
    the current vertex into lat/long.  Does it's longitude lie between the
    longitudes of the start and end point.  If yes, return to step 1) for
    the next vertex ... everything is fine.

3) We have determined that this line segment is suffering from 360 degree
    wrap to keep in the -180 to +180 range.  Now add or subtract 360 degrees
    as determined from the original sign of the distances.

This is similar to the code there now (though disabled in CVS); however,
it will ensure that big boxes will remain big, and not get dateline wrapped
because of the extra test in step 2).  However step 2 is invoked only very
rarely so this process takes little more than the normal process.  In fact,
if we were sufficiently concerned about performance we could do a test on the
shape MBR in lat/long space, and if the width is less than 180 we know we never
need to even do test 1).

What doesn't this resolve:

This ensures that individual lines are kept in the proper shape when
reprojected to geographic space.  However, it does not:

  o Ensure that all rings of a polygon will get transformed to the same "side"
    of the world.  Depending on starting points of the different rings it is
    entirely possible for one ring to end up in the -180 area and another ring
    from the same polygon to end up in the +180 area.  We might possibly be
    able to achieve this though, by treating the multi-ring polygon as a whole
    and testing the first point of each additional ring against the last
    vertex of the previous ring (or any previous vertex for that matter).

  o It does not address the need to cut up lines and polygons into distinct
    chunks to preserve the correct semantics.  Really a polygon that
    spaces the dateline in a -180 to 180 view should get split into two
    polygons.  We haven't addressed that, though if it were to be addressed,
    it could be done as a followon and distinct step from what we are doing
    above.  In fact this sort of improvement (split polygons based on dateline
    or view window) should be done for all lat/long shapes regardless of
    whether they are being reprojected from another projection.

  o It does not address issues related to viewing rectangles that go outside
    the -180 to 180 longitude range.  For instance, it is entirely reasonable
    to want a 160 to 200 longitude view to see an area on the dateline clearly.
    Currently shapes in the -180 to -160 range which should be displayed in the
    180 to 200 portion of that view will not be because there is no recogition
    that they belong there.

*/

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    | Geospatial Programmer for Rent



More information about the mapserver-users mailing list