0

Working on a prototype program - right now using the named regions from (https://download.geofabrik.de/) that are defined via a geojson (https://download.geofabrik.de/index-v1.json) to build maps based on a user's defined area (a simple rectangular area currently).

For now we are having the user go to the website and download the appropriate sized "named" region that will cover the area of interest. We can also do this programmatically with pyrosm, get_data call IF we know the correct name of the region that would cover that area of interest.

Is there a call within pyrosm, or another library, that could determine which named areas would provide complete coverage of the area of interest and then subsequently down them (via get_data, or other method).

Obviously we could search through the geojson file and some how determine which region(s) the coordinates fall within - easier with a single coordinate, tougher as the area of interest definition gets more complicated. Looking for the off-the-shelf or more robust answer, especially to find the smallest region.

geojson example data:

{ "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": { 
                "id" : "afghanistan",
                "parent" : "asia",
                "iso3166-1:alpha2" : [ "AF" ],
                "name" : "Afghanistan",
                "urls" : {
                    "pbf" : "https://download.geofabrik.de/asia/afghanistan-latest.osm.pbf",
                    "bz2" : "https://download.geofabrik.de/asia/afghanistan-latest.osm.bz2",
                    "shp" : "https://download.geofabrik.de/asia/afghanistan-latest-free.shp.zip",
                    "pbf-internal" : "https://osm-internal.download.geofabrik.de/asia/afghanistan-latest-internal.osm.pbf",
                    "history" : "https://osm-internal.download.geofabrik.de/asia/afghanistan-internal.osh.pbf",
                    "taginfo" : "https://taginfo.geofabrik.de/asia/afghanistan/",
                    "updates" : "https://download.geofabrik.de/asia/afghanistan-updates"
                }
            },
            "geometry": { "type" : "MultiPolygon", "coordinates" : [[[[62.478080,29.389570],[60.850480,29.858340],[61.787900,30.845590],

1 Answer 1

1

Looks like geopandas might do the trick... I'm sure I am going to get down voted for this not being the most efficient, but it is something to start with.

download the geojson from the link above.

import geopandas as gpd
from shapely.geometry import Point

# load the file into a geopandas dataframe
boundaries = gpd.read_file(r'C:\Folders\index-v1.json')

# then check if a specific point is contained within
found = boundaries.contains(Point(-84,39))

# see the results
boundaries[found]


    id  parent  name    urls    geometry
270     north-america   None    North America   {'pbf': 'https://download.geofabrik.de/north-a...   MULTIPOLYGON (((-114.55102 8.24342, -100.89097...
391     us  north-america   United States of America    {'pbf': 'https://download.geofabrik.de/north-a...   MULTIPOLYGON (((-80.64778 24.38628, -82.79447 ...
392     us-midwest  north-america   US Midwest  {'pbf': 'https://download.geofabrik.de/north-a...   MULTIPOLYGON (((-104.05300 49.00349, -95.18458...
432     us/ohio     north-america   us/ohio     {'pbf': 'https://download.geofabrik.de/north-a...   MULTIPOLYGON (((-83.10642 41.96397, -83.05735 ...

if you have multiple points, search them all as points and find where they overlap, or combine them into a polygon:

polygon = Polygon([(-84,39),(-84,40),(-83,40),(-83,39)])
found = boundaries.contains(polygon)
boundaries[found]

To find the smallest, calculate their area(s): areas = boundaries[found]['geometry'].area

270    9797.681428
391    3516.021731
392     235.916414
432      12.513964
dtype: float64

and find the min

smallest = areas.idxmin()
boundaries.iloc[smallest]

id                                                    us/ohio
parent                                          north-america
name                                                  us/ohio
urls        {'pbf': 'https://download.geofabrik.de/north-a...
geometry    (POLYGON ((-83.10642 41.96397, -83.05735 41.86...
Name: 432, dtype: object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.