Sunday, 15 October 2017

postgis - ST_DWithin uses Geometry or Geography type


assuming I use the following query to match the locations to a poi within 10km distance:


SELECT
poi.poi_id,

h.loc_id,
(ST_Distance(poi.geom,h.geom)*111.111) as distanceinkm
FROM iut_poi_transl AS poi, hrs_loc as h
WHERE poi.poigr_id != 30 AND ST_DWithin(poi.geom,h.geom,0.09)

Data is SRID 4326.


Does it use the geometry or the geography type?


If uses geometry how do I have to change the query to get use geography type?



Answer



as said before it uses the type it gets. so what you have to do is to feed it with geography. If your data is stored as geometry you can cast to geography on the fly



poi.geom::geography


SELECT
poi.poi_id,h.loc_id,
(ST_Distance(poi.geom::geography,h.geom::geography)/1000) as distanceinkm
FROM iut_poi_transl AS poi, hrs_loc as h
WHERE poi.poigr_id != 30 AND ST_DWithin(poi.geom::geography,h.geom::geography,10000)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...