Code Monkey home page Code Monkey logo

osm-road-length's Introduction

OSM Road Length

Maintenance yes PyPI version fury.io PyPI download total PyPI download month

DISCONTINUED! USE OSMPY https://github.com/JoaoCarabetta/osmpy

A tool to get the highway length from Open Street Maps of a region using Python using Overpass Turbo API.

It supports any region size and shape. From cities to continents.

Installing

Using

Why not OSMnx?

OSMnx is a great package if you want to analyse the road infrastructure in depth. But, sometimes we just want simple numbers to do comparissons. This package does not load all road data to memory (imagine loading a whole country to your RAM). The package fetches the Overpass API directly. If the region is too large, it splits the region in a smart way to handle the Overpass API constrains.

Credits

  • Free software: MIT license

Function katana from snorfalorpagus.

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

osm-road-length's People

Contributors

joaocarabetta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hyuanggg elebrux

osm-road-length's Issues

Qestion about: calculate min, avg, max width from polygons

Thanks for great repo.
I want to calculate min, max, avg width(breadth) from polygons.
My input have only list polygons:

{ "type": "Feature", "properties": { "OBJECTID": 1.0, "SHAPE_Leng": 0.00057672519222000005, "SHAPE_Area": 5.191152e-09, "name": null, "rongMax": null, "rongMin": null, "rongTB": null }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 105.814052974000049, 21.009160664000035 ], [ 105.814018928000053, 21.00919353200004 ], [ 105.814021210000078, 21.009195662000025 ], [ 105.814026385000034, 21.009202952000066 ], [ 105.81405440900005, 21.009242426000071 ], [ 105.814090260000057, 21.009269388000064 ], [ 105.814124937000088, 21.009292263000077 ], [ 105.814203617000032, 21.009343118000061 ], [ 105.814214316000061, 21.009350654000059 ], [ 105.814223964000064, 21.009340076000058 ], [ 105.814170518000083, 21.009304149000059 ], [ 105.81414109900004, 21.009282088000077 ], [ 105.814117868000039, 21.009266112000034 ], [ 105.814087328000085, 21.009244852000052 ], [ 105.814074111000082, 21.009232288000078 ], [ 105.814072411000041, 21.009232829000041 ], [ 105.814058327000055, 21.009186317000058 ], [ 105.814055345000043, 21.009175664000054 ], [ 105.814052974000049, 21.009160664000035 ] ] ] ] } }

Here I had drawn it to easy understand
image
Many thanks!!

Too complicated polygons

I recently widely used your package to calculate the road length of cities and entire countries. Thank you for this module, it was really helpful. However I found that when the geometry of the object is complicated so that query length is too long, Overpass API returns the error 414.

To fix that I modified a couple of functions:

in katana() I modified a constructor and the first if statement as follows with adding additional parameter urllen_threshold:
def katana(geometry, threshold_func, threshold_value, count=0, urllen_threshold=7648):
if (threshold_func(geometry, threshold_value) and (len(to_overpass_coords(geometry)) < urllen_threshold)) or count == 250:

Since it doesn't guarantee that url length will be short enough before the number of recursions can be exceeded, I also modified the beginning of get() function:

def get(geometry, threshold_value=1000000, urllen_threshold=7648):
    geometries = katana(geometry, threshold_func, threshold_value, urllen_threshold=urllen_threshold)
    
        while True:
            for geo in geometries:
                urllen = len(to_overpass_coords(geo))
                if urllen >= urllen_threshold:
                    geometries.remove(geo)
                    geometries.extend(katana(geo, threshold_func, threshold_value, urllen_threshold=urllen_threshold))
                    break
            else:
                break

        responses = []
        for geo in geometries:

Note: the value 7648 was found experimentally, perhaps this value can be higher, but definitely less than 8000.

get roads lengths in a city

  • S2-py version:
  • Python version: 3.7.7
  • Operating System: windows 10

Description

In you example code: you use wkt.loads() to create geometry and then get the roads lengths inside this geometry.
Could you also give some example of how to get the roads lengths inside a country?
Or I can only create some approximate geometry using latitudes and longitudes to do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.