1

Dear community, i am aware that the topic is discussed on several places - nevertheless i didn't find an answer up to now (sorry when i missed it). My goal is simply to count the total street length of all streets within a certain city (the exact district) for a running project. Two things i can't solve:

  1. I am not able to export ONLY a certain city district within its exact borders - like: https://www.openstreetmap.org/relation/959809#map=12/48.8367/13.0167 The information is there ... in theory it would be enough to export only the data with a certain regional or community key. I tried it with https://export.hotosm.org - but even with a certain export shape formed i do not get the correct data. So i do not look for a rectangle data - only the data within the city border.

  2. I can't find a solution to calculate the street length. In QGIS there is under vector/analytic-tools/summary line length - but this didn't get me any results and i am not sure if it counts only street length or every line. Than i found osm-length-2.pl but i could't get it to work - (besides the fact i do not have the right data). Sorry for this dummy question: I installed Perl - i have a OSM-file - i run osm-length-2.pl and how tell i the script to use my OSM-file? Within the script there is the info to use stdin - but i could't figure out HOW to use it and i am not a Perl-Programmer - sorry.

Appreciate any help - didn't thought it is so difficult :-O Christoph

asked 22 Apr '19, 20:16

KCBCOM's gravatar image

KCBCOM
26112
accept rate: 0%


4 Answers:
3

For a precise result, you cannot hope to cut out "all streets within a city" from OSM before you compute the length, because streets can cross the city boundary and if I understand you correctly, in this case you'd only want the length of the bit inside.

One way of getting this done is:

  1. Import OSM data for a rectangle around your city into a PostGIS database with osm2pgsql. This will not only give you the roads but also the city boundary if mapped in OSM.
  2. Use PostGIS to sum up the length of geometries inside your area of interest ("clipping polygon") as discussed in "Actual road length of exported map"

QGIS will also allow you to filter out all roads and clip them at the polygon boundary but it is a more cumbersome and manual process.

permanent link

answered 23 Apr '19, 09:27

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
73.3k866641137
accept rate: 24%

0

Thanks for your answer Frederik! After trying your solution it still turned out a little bit complicated for me. So now i came up with following workaround (QGIS 3.6.2):

  1. Install QuickOSM-Plugin. Make a search with key=highway and In=NameOfYourCity. Under additionale settings (Dropdown) i checked only Node, Way, Relation and Line. Run the query.
  2. The result will be a list of streets within your city - added in the layers panel. Now i made a right click on the new layer and opened the attribute table. Problem is: There are to many not valid streets (like private or motorway etc.) included. My solution was: A) Make the layer edible (Pen button). Sort by street name. Delete all streets without name. Rename the layer for this result. Problem now is: Some linking overland streets are missing B) Run the same query. Now delete all streets with name. Afterwards sort by highway and delete anything except primary, residential, secondary and tertiary.
  3. Finally for calculating the length i added a new field with the field calculator button in the attribute table. Fieldname=length_km, Fieldtype=decimal(real), Fieldlength=10, precision=2. In the query window add: $length / 1000. Than press ok - sort the new field from the end to the beginning if you want and close the attribute table.
  4. Open Vector/Analytic-Tools/Basic-Statistic-For-Fields. Choose your preferred layer for input and choose your new field lenght_km for calculation. Start the process. Under sum you can see the Km.

Step 3+4 are fully described here: http://www.qgistutorials.com/en/docs/calculating_line_lengths.html

Greetings - Christoph

permanent link

answered 24 Apr '19, 20:30

KCBCOM's gravatar image

KCBCOM
26112
accept rate: 0%

edited 24 Apr '19, 20:34

0

Yet another possiblity: you can run a query on Overpass API. This one produces a sample statistic for my home town, by value of highway. Length is in meters.

This should also point you to the real issues: You should decide for yourself whether you want to count footways and tracks or not. Another source of incertainty are dual carriageways; they would be counted twice because they are two ways in OpenStreetMap. Frontage roads, turn lanes and more may also affect the results. Finally, the request keeps ways on the boundary intact, thus slightly overestimating length values for that part of the problem.

Nontheless, for best effort guess data is for sure good enough.

permanent link

answered 26 Apr '19, 18:48

Roland%20Olbricht's gravatar image

Roland Olbricht
6.4k35986
accept rate: 35%

0

Have you tried this package?

https://github.com/JoaoCarabetta/osm-road-length

It is super easy,

Install it: pip install osm-road-length

And run:

import osm_road_length from shapely import wkt

geometry = wkt.loads('POLYGON((-43.2958811591311 -22.853167273541693,-43.30961406928735 -23.035275736044728,-43.115980036084224 -23.02010939749927,-43.157178766552974 -22.832917893834313,-43.2958811591311 -22.853167273541693))')

length = osm_road_length.get(geometry)

permanent link

answered 30 Apr, 22:29

JOAO%20LUIZ's gravatar image

JOAO LUIZ
1
accept rate: 0%

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:

×117
×91
×14

question asked: 22 Apr '19, 20:16

question was seen: 1,393 times

last updated: 30 Apr, 22:29

powered by OSQA