Dear all,

I define a polygon (Poly 1) which extends over the date line. Point 1 clearly 
is inside Poly 1.

geoDB=> SELECT ST_DWITHIN(ST_GeogFromText('POINT(180 0)'), 
ST_GeogFromText('POLYGON((170 -1, 190 -1, 190 1, 170 1, 170 -1))'), 0);
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for 
GEOGRAPHY
 st_dwithin
------------
 t
(1 row)

If I have a closer look at this polygon it shows the representation below.

geoDB=> SELECT ST_ASEWKT(ST_GeogFromText('POLYGON((170 -1, 190 -1, 190 1, 170 
1, 170 -1))'));
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for 
GEOGRAPHY
                        st_asewkt
---------------------------------------------------------
 SRID=4326;POLYGON((170 -1,-170 -1,-170 1,170 1,170 -1))
(1 row)



      -180             0               180

        |              |                |
        |              |                |
90 -----|--------------|----------------|----- 90
        |              |                |
        |              |                |
        |              |                |
        |              | Point2 (0/0)   | Point1 (180/0)
        |  ____________|______________ ____
 0 -----|-|____________*______________|_*__|-- 0
        |              |                |
        |              | Poly 2         | Poly 1
        |              |                |
        |              |                |
        |              |                |
-90-----|--------------|----------------|----- -90
        |              |                |
        |              |                |
      -180             0               180


If I look at the order of the coordinates it looks like Poly 2.

geoDB=> SELECT ST_DWITHIN(ST_GeogFromText('POINT(0 0)'), 
ST_GeogFromText('POLYGON((170 -1,-170 -1,-170 1,170 1,170 -1))'),0);
 st_dwithin
------------
 f
(1 row)

The test with Point 2 shows that this assumption is wrong. Again Point 1 is 
inside.

geoDB=> SELECT ST_DWITHIN(ST_GeogFromText('POINT(180 0)'), 
ST_GeogFromText('POLYGON((170 -1,-170 -1,-170 1,170 1,170 -1))'),0);
 st_dwithin
------------
 t
(1 row)

If I use the geometry data type instead of the geography data type Point 2 is 
clearly inside Poly 2.

geoDB=> SELECT ST_DWITHIN(ST_GeomFromText('POINT(0 0)'), 
ST_GeomFromText('POLYGON((170 -1,-170 -1,-170 1,170 1,170 -1))'),0);
 st_dwithin
------------
 t
(1 row)

And finally here is my question: How do I construct Poly 2 from these 
geographic points?

geoDB=> SELECT ST_ASEWKT(ST_GeogFromText('POLYGON((170 -1,-170 -1,-170 1,170 
1,170 -1))'));
                        st_asewkt
---------------------------------------------------------
 SRID=4326;POLYGON((170 -1,-170 -1,-170 1,170 1,170 -1))


Best regards and thanks for your help

Christian


P.S. A possible workaround is the use of vertices between the corner points, 
e.g.

SELECT ST_ASEWKT(ST_GeogFromText('POLYGON((170 -1, 0 -1, -170 -1, -170 1, 0 1, 
170 1, 170 -1))'));

geoDB=> SELECT ST_DWITHIN(ST_GeogFromText('POINT(0 0)'), 
ST_GeogFromText('POLYGON((170 -1, 0 -1, -170 -1, -170 1, 0 1, 170 1, 170 
-1))'),0);
 st_dwithin
------------
 t
(1 row)

For me this seems like a possible workaround, but not like a answer to the 
question above

_______________________________________________
postgis-users mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/postgis-users

Reply via email to