You are not logged in.

Announcement

*** NOTICE: forum.openstreetmap.org is being retired. Please request a category for your community in the new ones as soon as possible using this process, which will allow you to propose your community moderators.
Please create new topics on the new site at community.openstreetmap.org. We expect the migration of data will take a few weeks, you can follow its progress here.***

#1 2011-02-13 18:00:58

alobar72
Member
Registered: 2010-12-07
Posts: 13

closest way to user location

Hi all, I am playing around a bit with openstreetmap data. What I want to get is the closest "road" (i.e. way with tag 'highway' set to certain values) to the users position.
At the moment I use the API to query all Objects in a square around the user and then parse all the way elements, check their tags, check their distance to the user and so on
But that doesn't sound to elegant to me.
Is there a better solution ? maybe through the API or by installing the openstreetmap data in a local DB somehow to be able to query that directly ?

would be great if someone could point me to the right direction.

Thanks in advance.

Offline

#2 2011-02-13 18:38:05

JRA
Member
Registered: 2007-12-17
Posts: 677

Re: closest way to user location

After importing data into PostGIS with osm2pgsql these PostGIS recipes should work directly:
http://www.bostongis.com/?content_name= … or_generic
As article says, Oracle has special functions SDO_NN and SDO_NN_DISTANCE for this purpose.  Importing OSM data is not very simple because shere is no "osm2sdo" tool.  Most practical way would probably be to use osm2pgsl firts and then ogr2ogr for the PostGIS -> Oracle spatial conversion.  However, ogr2ogr does not have Oracle spatial support by default.

Offline

#3 2011-02-13 18:52:59

alobar72
Member
Registered: 2010-12-07
Posts: 13

Re: closest way to user location

Hi,

thanks for that response - sounds promissing, I'll look into it

Offline

#4 2011-02-14 13:18:33

SK53
Member
Registered: 2009-01-11
Posts: 705

Re: closest way to user location

I would think it is possible to achieve what you want using native PostGis functions such as ST_ShortestPath. In general if you assume users live on roads then a buffer of 100metres is likely to encompass any candidate features. So look for ways with appropriate tags within a chosen buffer distance from user location & select MIN(ST_ShortestPath(highway_way,user_node).

Offline

Board footer

Powered by FluxBB