A
A
Anton Shelestov2018-02-06 16:03:28
MySQL
Anton Shelestov, 2018-02-06 16:03:28

Determining the distance between points and entering a point into a polygon?

People are confused with geometric objects in mysql
For example

SELECT ST_Distance_Sphere(ST_GeomFromText('POINT(59.92221140264606 30.33592959805362 )'), ST_GeomFromText('POINT( 59.91757448179685 30.34996245507689 )')) as distance

Result: 1622.5853896756541 meters which is not correct.
If at each point the coordinates are interchanged, then: 936.7446267405903 meters and That's right!
Next, a query for determining whether a point enters a polygon:
SELECT ST_Within(ST_GeomFromText('POINT(59.92221140264606 30.33592959805362 )'), ST_GeomFromText('POLYGON((59.960439 30.155863,59.970939 30.183329,60.00551300831579 30.30108880468746,59.97782267102391 30.418505281249995,59.90478568802594 30.452150609374957,59.873384939513095 30.331301148437454,59.890813753470574 30.22040838085935,59.912545 30.191226,59.924611 30.157924,59.945285999999996 30.139728,59.960439 30.155863))')) as inner_point

Result: the point is included in the polygon
BUT if you change the order of coordinates in the point, then the point will no longer be included in the polygon !!
What is the problem: The problem is in the order of the coordinates of the points.
1. distance is not exact - the point is included in the polygon
2. distance is exact - the point is not included in the polygon.
Can anyone suggest how to overcome this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Milliard, 2018-02-15
@Milliard

In a spherical system, the coordinates are not equivalent. When changing the order of coordinates, the distance between points will differ.
As an example: two points with a latitude of 90 °, any longitude. The distance between points is always zero. We change the order of coordinates: the longitude is 90 ° and the distance is no longer zero, but directly depends on the latitudes of the points.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question