So the problem is that I have a set of multipolygons and points and I need to be able to query the data with a given point to check which ones are within 'x' km.

Initially my SRID was 4283 but I was unable to figure out a way to use the PtDistWithin function with meters as it used degrees. I tried loading the data with a SRID of 3577 which should be in meters and querying but I don't get a sensible result. The query below is my attempt to get the data with 3577 SRID data.

select * from geotable where PtDistWithin(Transform(PointFromText('POINT(144.963, -37.8136)', 4283), 3577), geotable.geom, 10000);

This however does not return any result when I know there should be a number of results returned within 10 km of this point.

Note: I know there is an approximate conversion between degrees and meters but am looking for a cleaner solution.


Usage of PtDistWithin is documented in http://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html

return TRUE (1) if the distance between geom1 and geom2 is within the given range. Usually distances are expressed in the length unit corresponding to the geoms own SRID: but if both geoms are simple POINTs and their SRID is 4326 (i.e. WGS84), then distances are expressed in meters. In this later case the optional arg use_spheroid can be used to select the distance algorithm to be used: is use_spheroid = 1 the slowest but most accurate geodesic distance will be evaluated: in any other case the simplest great circle distance will be used instead

SpatiaLite is feature-rich but it seems that it can't handle your use case with PtDistWithin because you have multipolygons. If your data are within the valid area of EPSG:3577 you can make a conversion into that. Othewise you may have a try with another function "Distance" in query SELECT...FROM...WHERE Distance(geom1,geom2)<10000. I am not sure if you can use EPSG:4283 with that function or if you must transform it into EPSG:4326.

return the distance between geom1 and geom2 (measured in meters). If the use_ellipsoid argument is set to TRUE the precise (but slower) distance will be computed on the Ellipsoid, otherwise will be computed on the Great Cicle (approximative, but faster).

This function only supports Long/Lat coordinates, and will return NULL for any planar CRS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.