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 2009-09-20 12:39:54

herteby
Member
Registered: 2009-09-20
Posts: 1

Finding roads by length

Is there a way to find roads based on their length, or getting a list of roads in an area together with their lengths?

Offline

#2 2009-09-21 11:29:36

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

Re: Finding roads by length

Hi,


If is rather simple if you can tolerate importing OSM data first into PostGIS database with osm2pgsql utility.  In that case read first
http://www.mail-archive.com/talk@openst … 15189.html

Basic query for getting a length of an OSM object is like

select ST_length_spheroid(transform(way,4326),
'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]]') as
length from planet_osm_line where osm_id=-31332;

The query should be adjusted a bit to group all the road sections having a common name together.
select name, sum(ST_length_spheroid(transform(way,4326),
'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]]')) as
length from planet_osm_line
WHERE highway in not null
GROUP BY name
ORDER BY name;

Not guaranteed that this is exactly correct and at least one problem remains: dual carriage ways would give the road length doubled.  And of course this query is missing the spatial part limiting the area to what you are interested in.

There are probably also tools which can calculate lengths directly from OSM xml files.

Offline

Board footer

Powered by FluxBB