Giter Site home page Giter Site logo

osmpy's Introduction

Powerfull wrapper around OSM Overpass Turbo to query regions of any size and shape

pip install osmpy

List precooked queries

osmpy.list_queries()

            name                                          docstring
0      Amenities           Location of amenities within a boundary 
1  AmentiesCount    Number of amenities per type within a boundary 
2           POIs   Location of Points of Interest within a bound...
3     RoadLength      Length of road by roadtype within a boundary 

Get all Points of Interest (POIs) within a boundary

import osmpy
from shapely import wkt

boundary = wkt.loads('POLYGON((-46.63 -23.54,-46.6 -23.54,-46.62 -23.55,-46.63 -23.55,-46.63 -23.54))')
osmpy.get('POIs', boundary)

    type          id        lat        lon                                               tags                      poi
0   node   661212030 -23.544739 -46.626160           {'amenity': 'fuel', 'name': 'Posto NGM'}             amenity:fuel
1   node   661212089 -23.547450 -46.626073  {'amenity': 'fuel', 'name': 'Posto Maserati', ...             amenity:fuel
2   node   745733280 -23.541411 -46.613930  {'addr:city': 'São Paulo', 'addr:housenumber':...             amenity:bank
3   node   745733292 -23.542070 -46.614916  {'addr:city': 'São Paulo', 'addr:housenumber':...             amenity:bank
4   node   889763809 -23.542558 -46.620360  {'addr:housenumber': '110/C9', 'addr:street': ...    amenity:social_centre
..   ...         ...        ...        ...                                                ...                      ...
82  node  5663737625 -23.540027 -46.605425  {'access': 'yes', 'addr:city': 'São Paulo', 'a...          amenity:parking
83  node  5990269247 -23.540650 -46.607532  {'addr:city': 'São Paulo', 'addr:housenumber':...        amenity:fast_food
84  node  6621564995 -23.543880 -46.626414  {'access': 'yes', 'addr:city': 'São Paulo', 'a...          amenity:parking
85  node  6625433725 -23.546727 -46.623956  {'access': 'yes', 'addr:city': 'São Paulo', 'a...          amenity:parking
86  node  6625433753 -23.547111 -46.624790  {'access': 'yes', 'addr:city': 'São Paulo', 'a...  amenity:bicycle_parking

Total road length in meters by road type

osmpy.get('RoadLength', boundary)

               count     length
highway                        
bus_stop           1     82.624
corridor           2    482.195
cycleway           1    134.197
footway          116   5473.419
living_street      3    422.378
path               4    735.539
pedestrian         3     90.327
platform           3    239.206
primary           28   2067.562
primary_link      12   1123.544

You can use your own query

## Use `{boundary}` as a placeholder.
query = """
    [out:json];
    node["amenity"](poly:"{boundary}");
    out body geom;
    """

osmpy.get(query, boundary)

Create a precooked query

class YourPrecookedQuery(osmpy.queries.QueryType):

    query = """
    <OSM Overpass Turbo Query>
    """

    docstring = """
    <Query description>
    """

    def postprocess(self, df):
        """Post process API result
        """
        return df['tags'].apply(pd.Series).groupby('amenity').sum()

osmpy.get(YourPrecookedQuery, boundary)

👉 Leave an issue or PR if you want to add a new query to the package

Credits

Function katana from @snorfalorpagus_.

osmpy's People

Contributors

joaocarabetta avatar

Stargazers

Pedro Augusto Borges dos Santos avatar  avatar Dominik Antal avatar Andrei Cusiac avatar Chase avatar Anthony Rentsch avatar Lucas Farias avatar Aissa Hadj Mohamed avatar JacquesB. avatar  avatar suprnrdy avatar Tigran avatar Lars Schwarz avatar Thomas Gratier avatar Alper Dincer avatar André Kruger avatar Alex Hafner avatar

Watchers

James Cloos avatar  avatar

osmpy's Issues

Unit of measure of the Road Length

  • Python version: 3.10
  • Operating System: Windows

Description

Hi, I am measuring the total length of road networks and I would kindly ask you what is the unit of measure of the length given by the "osmpy.get('RoadLength', boundary)" function. It is in meters? km?

Thank you,
Juan

osmpy getting stuck in katana function

  • S2-py version: osmpy==0.2.0
  • Python version: Python 3.8.10
  • Operating System: Ubuntu 20.04.1 LTS

Description

I am trying to find the ways within the given polygon.
Program is getting stuck.

What I Did

import osmpy
from shapely import wkt
boundary = wkt.loads('POLYGON((37.8413 -122.2790,37.8545 -122.2790,37.8545 -122.2963,37.8413 -122.2963,37.8413 -122.2790))')

query = """[out:json];    way["highway"](poly:"{boundary}");    out body geom;"""
res = osmpy.get(query, boundary)
print(f"{res}")

Further when I was looking at the library found the following function katana being called recursively and not exiting.

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.