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

Hi,

I am pretty new to OSM and GIS, i wondering how can i determine if a given point(lat,lon) is in a road segment or out.

Further explanation on what i want to achieve :

I have a reference point(lat1,lon1). I determine a circle with a radius of 30 meters, and a center (lat1, lon1). if want to know if this circle intersect roads.

Any tips will be welcome !

Regards,

Julien

asked 02 Jul '13, 04:31

Julzen's gravatar image

Julzen
26113
accept rate: 0%

1

Could you please tell more

  • do you want to do this rather once or rather automatically hundreds of times per second?

  • do you want an offline service with local data or rather an online service?

(02 Jul '13, 08:37) Roland Olbricht
1

Hi Roland,

I want to do this automatically hundreds of times and i want an offline service.

Hope this would help!

(02 Jul '13, 11:36) Julzen

The following will give you the most accurate results:

  • Import data into PostGIS, possibly with osm2pgsql but others exist; for faster import, modify osm2pgsql's style file so that only roads are imported
  • in the resulting table - called planet_osm_line if you use osm2pgsql -, add a column of type "geography" that copies the contents of the existing "geometry" type column (e.g. alter table planet_osm_line add column mygeographycolumn geography; update planet_osm_line set mygeographycolumn=way;)
  • create a spatial index on the "geography" column
  • now query the database like this: select name,osm_id,highway from planet_osm_line where ST_DWITHIN(mygeographycolumn, ST_SETSRID(ST_POINT(lon1,lat1),4326)::geography, dist) (replace lon1, lat1, dist by your coordinates and radius of circle).

You can skip the whole "convert to geography" bit and use a suitable projection for your area of interest which will then usually yield results in the +/- 1 metre range; if you go with the default projection of Spherical Mercator and your area of interest is far away from the Equator you will be searching ellipses, not circles.

SQL statements in this answer written from memory - not syntax proofed.

permanent link

answered 02 Jul '13, 21:13

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

So you have the OSM road network and want to ask for some coordinate whether a road is (less than) 30 meters away?

The relevant GIS terminology would probably be "buffering" (this is drawing the circle of 30m around your point) and "intersection testing" (to see whether a road intersects the buffer around the point).

There are a few options for choosing software for that task.

You could use a Desktop GIS like Quantum GIS, and then script your analysis with e.g. python scripting. This will have a steep learning curve if you never used a GIS before.

You could import all OSM data into a PostGIS DB and then make the spatial queries using SQL, this would work better if you had a "working knowledge" of SQL.

permanent link

answered 02 Jul '13, 13:29

gormo's gravatar image

gormo
2.9k32660
accept rate: 13%

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×223
×49
×9

question asked: 02 Jul '13, 04:31

question was seen: 4,141 times

last updated: 02 Jul '13, 21:13

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