NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I see that you can use nominatim with an HTTP POST for this. However, I went to the trouble of loading the OSM database into postgres, and I want to take advantage of the speed of querying it from my DB, without an HTTP call.

Is there a SQL QUERY that can get the osm_ids associated with a specific latitude/longitude??

Thanks so much. Ive spend dozens of hours trying to figure this out!

asked 14 Nov '12, 02:22

sfrattura's gravatar image

accept rate: 0%

This depends on how you have imported the data. For an osm2pgsql import, the query would look like this:

   planet_osm_point (or _line, or _polygon)
   ST_DWITHIN(mypoint, way, mydistance);

What you put for mypoint and mydistance depends on what projection your data is in; if you have imported without -l, i.e. your data is in spherical mercator, you would have to put something like

ST_TRANSFORM(ST_SETSRID(ST_MAKEPOINT(mylon, mylat), 4326), 900913)

and for mydistance you would put the distance in spherical mercator units, i.e. roughly metres.

The query will then return all IDs within the given distance of the point.

permanent link

answered 14 Nov '12, 08:16

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

I have a simliar problem trying to show some localities only having the lat long data availabe. Can you point me to a different resolution for this problem. I'm using mapserver on windows and openlayers. Thank you

permanent link

answered 13 Mar '14, 09:18

Victor1989's gravatar image

accept rate: 0%

This is a completely different question, and you'd be better off asking it as a separate question, fully explaining what you want to do and what your setup is.

(13 Mar '14, 10:01) Richard ♦

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 14 Nov '12, 02:22

question was seen: 5,863 times

last updated: 13 Mar '14, 10:01

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum