Geography point to polygon st_distance for a polygon crossing the equator

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Geography point to polygon st_distance for a polygon crossing the equator

Sebastien Delaux
Hi all,

I am new to postgis and I am interested in finding all the points that are located at x metres or less of a polygon that are stored in my postgres database.
As I am working with data located all over the world and want to work with distances in metres I decided to use the geography type.

I am trying to understand why the following query returns 0 when the point is clearly not included in the polygon:
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))'));

I suspect this has something to do with the polygon crossing the equator as
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 -10, -90 -10, -90 -80))'));
returns a plausible distance.

Would anybody know whether my polygon is violating some assumption or whether there is any other reason that I am getting those results?

Thanks

Sebastien







_______________________________________________
postgis-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Geography point to polygon st_distance for a polygon crossing the equator

Paul Ramsey-3
I don't the polygon you've draw means what you think it does. 

POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))

For example, you probably figure the first segment, -90 -80, 90 -80 runs east-west between two points close to the south pole. In fact, it runs directly over the south pole, so actually to the south of your point of interest. 

P


On Sun, Feb 19, 2017 at 7:36 PM, Sebastien Delaux <[hidden email]> wrote:
Hi all,

I am new to postgis and I am interested in finding all the points that are located at x metres or less of a polygon that are stored in my postgres database.
As I am working with data located all over the world and want to work with distances in metres I decided to use the geography type.

I am trying to understand why the following query returns 0 when the point is clearly not included in the polygon:
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))'));

I suspect this has something to do with the polygon crossing the equator as
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 -10, -90 -10, -90 -80))'));
returns a plausible distance.

Would anybody know whether my polygon is violating some assumption or whether there is any other reason that I am getting those results?

Thanks

Sebastien







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


_______________________________________________
postgis-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Geography point to polygon st_distance for a polygon crossing the equator

Sebastien Delaux
Thanks for your reply Paul.
Yes, that's what I thought. That would explain why (0,-82) is inside the polygon.
Nevertheless, if my first segment runs through the south pole, then I would expect both of the queries mentioned in my initial post to return 0 which is not the case.

Sebastien

On Mon, Feb 20, 2017 at 4:56 PM, Paul Ramsey <[hidden email]> wrote:
I don't the polygon you've draw means what you think it does. 

POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))

For example, you probably figure the first segment, -90 -80, 90 -80 runs east-west between two points close to the south pole. In fact, it runs directly over the south pole, so actually to the south of your point of interest. 

P


On Sun, Feb 19, 2017 at 7:36 PM, Sebastien Delaux <[hidden email]> wrote:
Hi all,

I am new to postgis and I am interested in finding all the points that are located at x metres or less of a polygon that are stored in my postgres database.
As I am working with data located all over the world and want to work with distances in metres I decided to use the geography type.

I am trying to understand why the following query returns 0 when the point is clearly not included in the polygon:
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))'));

I suspect this has something to do with the polygon crossing the equator as
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 -10, -90 -10, -90 -80))'));
returns a plausible distance.

Would anybody know whether my polygon is violating some assumption or whether there is any other reason that I am getting those results?

Thanks

Sebastien







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


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



_______________________________________________
postgis-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Geography point to polygon st_distance for a polygon crossing the equator

Paul Ramsey-3
:) :) :)

Your second polygon has the same problem as the first, except in reverse... Your second polygon basically covers no area at all, since it consists of two arcs that both do a direct southerly run to the south pole.

P.


On Sun, Feb 19, 2017 at 8:09 PM, Sebastien Delaux <[hidden email]> wrote:
Thanks for your reply Paul.
Yes, that's what I thought. That would explain why (0,-82) is inside the polygon.
Nevertheless, if my first segment runs through the south pole, then I would expect both of the queries mentioned in my initial post to return 0 which is not the case.

Sebastien

On Mon, Feb 20, 2017 at 4:56 PM, Paul Ramsey <[hidden email]> wrote:
I don't the polygon you've draw means what you think it does. 

POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))

For example, you probably figure the first segment, -90 -80, 90 -80 runs east-west between two points close to the south pole. In fact, it runs directly over the south pole, so actually to the south of your point of interest. 

P


On Sun, Feb 19, 2017 at 7:36 PM, Sebastien Delaux <[hidden email]> wrote:
Hi all,

I am new to postgis and I am interested in finding all the points that are located at x metres or less of a polygon that are stored in my postgres database.
As I am working with data located all over the world and want to work with distances in metres I decided to use the geography type.

I am trying to understand why the following query returns 0 when the point is clearly not included in the polygon:
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))'));

I suspect this has something to do with the polygon crossing the equator as
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 -10, -90 -10, -90 -80))'));
returns a plausible distance.

Would anybody know whether my polygon is violating some assumption or whether there is any other reason that I am getting those results?

Thanks

Sebastien







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


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



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


_______________________________________________
postgis-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Geography point to polygon st_distance for a polygon crossing the equator

Sebastien Delaux
Thanks Paul, I get it now.
So I guess, it all comes from the fact that an arc is defined as the shortest path between 2 points which in the geometry case is a straight line and in the geography case is a great circle.
This also mean that "the polygon I had in mind" cannot be defined as a geography polygon.

S.

On Tue, Feb 21, 2017 at 6:03 AM, Paul Ramsey <[hidden email]> wrote:
:) :) :)

Your second polygon has the same problem as the first, except in reverse... Your second polygon basically covers no area at all, since it consists of two arcs that both do a direct southerly run to the south pole.

P.


On Sun, Feb 19, 2017 at 8:09 PM, Sebastien Delaux <[hidden email]> wrote:
Thanks for your reply Paul.
Yes, that's what I thought. That would explain why (0,-82) is inside the polygon.
Nevertheless, if my first segment runs through the south pole, then I would expect both of the queries mentioned in my initial post to return 0 which is not the case.

Sebastien

On Mon, Feb 20, 2017 at 4:56 PM, Paul Ramsey <[hidden email]> wrote:
I don't the polygon you've draw means what you think it does. 

POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))

For example, you probably figure the first segment, -90 -80, 90 -80 runs east-west between two points close to the south pole. In fact, it runs directly over the south pole, so actually to the south of your point of interest. 

P


On Sun, Feb 19, 2017 at 7:36 PM, Sebastien Delaux <[hidden email]> wrote:
Hi all,

I am new to postgis and I am interested in finding all the points that are located at x metres or less of a polygon that are stored in my postgres database.
As I am working with data located all over the world and want to work with distances in metres I decided to use the geography type.

I am trying to understand why the following query returns 0 when the point is clearly not included in the polygon:
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 10, -90 10, -90 -80))'));

I suspect this has something to do with the polygon crossing the equator as
SELECT ST_Distance(ST_GeographyFromText('SRID=4326;POINT(0. -82.)'),ST_GeographyFromText('SRID=4326;POLYGON((-90 -80, 90 -80, 90 -10, -90 -10, -90 -80))'));
returns a plausible distance.

Would anybody know whether my polygon is violating some assumption or whether there is any other reason that I am getting those results?

Thanks

Sebastien







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


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



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


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



--




_______________________________________________
postgis-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Geography point to polygon st_distance for a polygon crossing the equator

Paul Ramsey-3
That's right, we don't have a way to differentiate between great-circle edges and loxodromes on geography (or vice versa in geometry).

​You can approximate a "square"  by densifying your east-west lines in the places you want vertices to go, but the inter-vertex edges will still be great circles. You can do that by densifying in geometry land and then casting back to geography.

P.

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