Postgis - st_distance

I'm having problems with the st_distance function in postgis. It returns incorrect results - for small distances the error is not large - 10, maybe 20 meters, but for large distances the difference between my results and, for example, the results of Google Maps is too great - from 700 meters to 2 kilometers and above. I use srid = 4326. And, secondly, it is possible that the problem is - let's say I have a place that is 4 kilometers away. Postgis says ~ 0.0417 {{some_units}} away. Now I just multiply the result by 100 and get more or less accurate results. Can I pass some argument to this function that would say "return value in kilometers / meters"?

ps. postgres version - 9.0.1

+3
source share
6 answers

You should use a geography data type.

Using the function used by the geometry type, you get the same block as the data. In your cases degrees.

degrees cannot be transferred to counters in any simple way. To get the result in meters from the non-designed reference system, the calculation must be calculated on the "big circle" around the roughness of the earth. The calculation you use simply uses the Pythagorean theorem to calculate the distance in the plane.

So, PostGIS does not give the wrong result. You can move on to a meter-based spatial reference system, depending on whether your data covers a large area, so rounding the globe is a problem. If so, you should use the geography data type and use srid 4326.

NTN

Niklas

+3

, , ST_transform :

    ST_Distance(st_transform(ST_GeometryFromText('POINT(longitude     latitude)',4326),900913),st_transform(point,900913)) 
+1

, , , srid , 900913. , ( srid = 4326) 100, - .

, , srid , - , SRID - 21781. : http://gothos.info/tag/coordinate-systems/ srids .

0

Nicklas'answer, , srid 4326, :

select st_distance(geom1::geography,geom2::geography)

, , crs, EPSG: 25832 ETRS89/UTM zone 32N:

select st_distance(st_transform(geom1,25832),st_transform(geom2,25832))
0

SRID: 4326 ie.WGS1984 . , , UTM.

spatial_ref_sys

, , SRID . u, UTM. utm utmzone. .

select st_distance(st_transform(geom1,utmzone(geom1)),st_transform(geom2,utmzone(geom2)))
0

, geom sal sal . long long, :

select st_distance(point1,point2) from 
(SELECT ST_GeogFromText('SRID=4326;POINT(0 0)') point1,  
ST_GeogFromText('SRID=4326;POINT(0.25 0.4)') point2) a
0

All Articles