Exemple #1
0
def test_pois():

    import pytest
    # download all points of interests from place
    gdf = ox.pois_from_place(place='Kamppi, Helsinki, Finland')

    # get all restaurants and schools from place
    restaurants = ox.pois_from_place(place='Emeryville, California, USA', amenities=['restaurant'])
    schools = ox.pois_from_place(place='Emeryville, California, USA', amenities=['school'])

    # get all universities from Boston area (with 2 km buffer to cover also Cambridge)
    boston_q = "Boston, Massachusetts, United States of America"
    boston_poly = ox.gdf_from_place(boston_q, buffer_dist=2000)
    universities = ox.pois_from_polygon(boston_poly.geometry.values[0], amenities=['university'])

    # by point and by address
    restaurants = ox.pois_from_point(point=(42.344490, -71.070570), distance=1000, amenities=['restaurant'])
    restaurants = ox.pois_from_address(address='Emeryville, California, USA', distance=1000, amenities=['restaurant'])

    # should raise an exception
    # polygon or -north, south, east, west- should be provided
    with pytest.raises(ValueError):
        ox.create_poi_gdf(polygon=None, north=None, south=None, east=None, west=None)

    gdf = ox.pois_from_place(place='kusatsu, shiga, japan', which_result=2)
Exemple #2
0
    def get_trail_pois_for_polygon(self, polygon: Polygon):
        useful_tags_node = ox.settings.useful_tags_node
        useful_tags_node.extend(
            ['historic', 'wikipedia', 'tourism', 'backcountry'])
        ox.config(useful_tags_node=useful_tags_node)

        tags = {
            'amenity': [
                'shelter',
                'shower',
                'toilets',
            ],
            'natural': [
                'peak',
                'saddle',
            ],
            'toilets:disposal': [
                'pitlatrine',
                'flush',
            ],
            'tourism': [
                'alpine_hut',
                'camp_site',
                'picnic_site',
                'viewpoint',
                'wilderness_hut',
            ],
        }  # yapf: ignore

        gdf = ox.create_poi_gdf(polygon=polygon, tags=tags)

        # Some geometries are polygons, so replace geometry with its centroid.
        # For Points this makes no difference; for Polygons, this takes the
        # centroid.
        gdf.geometry = gdf.geometry.centroid

        # TODO: keep only useful columns?
        return gdf
Exemple #3
0
    def get_town_pois_for_polygon(self, polygon: Polygon):
        """Get Point of Interests from OSM for polygon

        Note: this function requires https://github.com/gboeing/osmnx/pull/342
        to be merged. For now, I use my own fork.

        Args:
            - polygon: polygon to search within
            - poi_type: either 'town', 'trail', or None.
        """
        useful_tags_node = ox.settings.useful_tags_node
        useful_tags_node.extend([
            'historic', 'wikipedia', 'tourism', 'internet_access',
            'washing_machine', 'phone', 'website'
        ])
        ox.config(useful_tags_node=useful_tags_node)

        tags = {
            'amenity': [
                # Sustenance
                'bar',
                'biergarten',
                'cafe',
                'drinking_water',
                'fast_food',
                'ice_cream',
                'pub',
                'restaurant',
                # Financial
                'atm',
                'bank',
                # Healthcare
                'clinic',
                'hospital',
                'pharmacy',
                # Others
                'post_office',
                'ranger_station',
                'shower',
                'toilets',
            ],
            'shop': [
                # Food, beverages
                'bakery',
                'convenience',
                # General store, department store, mall
                'general',
                'supermarket',
                'wholesale',
                # Outdoors and sport, vehicles                '',
                'outdoor',
                'sports',
                # Others
                'laundry',
            ],
            'tourism': [
                'camp_site',
                'hostel',
                'hotel',
                'motel',
                'picnic_site',
            ],
        }  # yapf: ignore

        gdf = ox.create_poi_gdf(polygon=polygon, tags=tags)

        # Drop a couple columns
        keep_cols = [
            'osmid', 'geometry', 'name', 'amenity', 'tourism', 'shop',
            'website', 'cuisine', 'opening_hours', 'brand:wikidata',
            'internet_access', 'internet_access:fee', 'addr:housenumber',
            'addr:street', 'addr:unit', 'addr:city', 'addr:state',
            'addr:postcode'
        ]
        keep_cols = [x for x in keep_cols if x in gdf.columns]
        gdf = gdf.filter(items=keep_cols, axis=1)

        if len(gdf) == 0:
            return gdf

        # Keep only rows with a non-missing name
        if 'name' in gdf.columns:
            gdf = gdf.loc[gdf['name'].notna()]

        if len(gdf) == 0:
            return gdf

        # Some geometries are polygons, so replace geometry with its centroid.
        # For Points this makes no difference; for Polygons, this takes the
        # centroid.
        gdf.geometry = gdf.geometry.centroid

        return gdf