I am using OSM and facing an issue with finding the nearest road-segments to a given lat/lon point.

I have a code that uses Java Spatial Index JSI which traverses the RTree index while computing the distance between the lat/lon point and the bounding rectangle of the objects using the distance-function.

Now I am trying to implement the same functionality using PostGIS. After some reading I ended up with the following SQL query:

SELECT osm_id FROM planet_osm_line 
WHERE way <#> ST_Transform(ST_SetSRID(ST_MakePoint(:plon, :plat), 4326), 900913) < :range

where :range is the max distance in meters.

My questions are

  1. Is the use of the <#>? my understanding is that this function would calculate the distance to the edges of the BB, although I don't know how exactly.
  2. Is the transformation to 900913 correct? Does this compute the distance between 2 geometries or geographies? I am confused with the relation between SRIDs and the use of geography in the computations of distances.
  3. Does using the <#> in the WHERE clause utilize the index of the table? I found some references stating that the function will utilize the index only when used with ORDER BY clause.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.