Amandasaurus
Amandasaurus

Reputation: 60809

What unit does Spatialite's Distance() function return?

Spatialite has a the ability to calculate the distance between 2 geometries with it's Distance() function. There are other functions that work on LINESTRINGs. However I can't find out what units it returns it in. Is it metres? If I have 2 points, how do I calculate the distance between them in a spatialite query?

(For the record I'm using SRID 4326, i.e. WSG 86, i.e. the old traditional degrees of latitude and longitude).

Upvotes: 3

Views: 3660

Answers (2)

Stefan
Stefan

Reputation: 1036

In version 2.4.4 and higher there is a function PtDistWithin() which returns meters for a distance query. See doc. section "SQL functions for distance relationships": http://www.gaia-gis.it/spatialite-2.4.0-4/spatialite-sql-2.4-4.html#p13

Upvotes: 0

Sandro Furieri
Sandro Furieri

Reputation: 126

the unit returned by ST_Distance(), ST_Length() and ST_Area() exactly is the one defined by the corresponding SRID.

consequently, if you are using latitude and longitude (SRID=4326, WGS 84), any length will be measured in DEGREES, and any area in SQUARE DEGREES.

if you are interested in giving a more conventional unit (METERS, SQUARE METERS), you simply have to project your geometries into some appropriate 'planar' CRS (e.g. UTM) using ST_Transform()

Upvotes: 11

Related Questions