Esempio n. 1
0
def test_parsing_basic_elements_from_pbf(test_pbf):
    from pyrosm import OSM
    import numpy as np
    osm = OSM(filepath=test_pbf)
    osm._read_pbf()
    nodes, ways = osm._nodes, osm._way_records

    assert isinstance(nodes, list)
    assert isinstance(ways, list)

    # Required node columns
    node_cols = [
        'id', 'version', 'changeset', 'timestamp', 'lon', 'lat', 'tags'
    ]
    for col in node_cols:
        for node_set in nodes:
            assert col in node_set.keys()
            # Nodes should be in numpy arrays
            assert isinstance(node_set[col], np.ndarray)

            # Check shape
            assert len(node_set[col]) in [6222, 8000]

    # Check ways shape
    assert len(ways) == 2653
    for way in ways:
        assert isinstance(way, dict)

    # Required way columns
    way_cols = ['id', 'version', 'timestamp', 'nodes']
    for way in ways:
        for col in way_cols:
            assert col in way.keys()
Esempio n. 2
0
def test_parsing_landuse_with_defaults(test_pbf):
    from pyrosm import OSM
    from pyrosm.landuse import get_landuse_data
    from geopandas import GeoDataFrame
    import pyproj
    from pyrosm._arrays import concatenate_dicts_of_arrays
    osm = OSM(filepath=test_pbf)
    osm._read_pbf()
    tags_as_columns = osm.conf.tags.landuse

    nodes = concatenate_dicts_of_arrays(osm._nodes)
    gdf = get_landuse_data(nodes,
                           osm._node_coordinates,
                           osm._way_records,
                           osm._relations,
                           tags_as_columns,
                           None,
                           None)

    assert isinstance(gdf, GeoDataFrame)

    # Required keys
    required = ['id', 'geometry']
    for col in required:
        assert col in gdf.columns

    # Test shape
    assert len(gdf) == 50
    assert gdf.crs == pyproj.CRS.from_epsg(4326)
Esempio n. 3
0
def test_parsing_pois_with_defaults(helsinki_pbf, default_filter):
    from pyrosm import OSM
    from pyrosm.pois import get_poi_data
    from geopandas import GeoDataFrame
    import pyproj
    from pyrosm._arrays import concatenate_dicts_of_arrays
    osm = OSM(filepath=helsinki_pbf)
    osm._read_pbf()
    tags_as_columns = []
    for k in default_filter.keys():
        tags_as_columns += getattr(osm.conf.tags, k)

    nodes = concatenate_dicts_of_arrays(osm._nodes)
    gdf = get_poi_data(nodes, osm._node_coordinates, osm._way_records,
                       osm._relations, tags_as_columns, default_filter, None)

    assert isinstance(gdf, GeoDataFrame)

    # Required keys
    required = ['id', 'geometry']
    for col in required:
        assert col in gdf.columns

    # Test shape
    assert len(gdf) == 1782
    assert gdf.crs == pyproj.CRS.from_epsg(4326)
def test_creating_building_geometries(test_pbf):
    from pyrosm import OSM
    from pyrosm.data_manager import get_osm_data
    from pyrosm.geometry import create_way_geometries
    from numpy import ndarray
    from pygeos import Geometry

    osm = OSM(filepath=test_pbf)
    osm._read_pbf()
    custom_filter = {"building": True}
    nodes, ways, relation_ways, relations = get_osm_data(
        None,
        osm._way_records,
        osm._relations,
        osm.conf.tags.building,
        custom_filter,
        filter_type="keep")
    assert isinstance(ways, dict)

    geometries, lengths, from_ids, to_ids = create_way_geometries(
        osm._node_coordinates, ways, parse_network=False)
    assert isinstance(geometries,
                      list), f"Type should be list, got {type(geometries)}."
    assert isinstance(geometries[0], Geometry)
    assert len(geometries) == len(ways["id"])
Esempio n. 5
0
def test_getting_nodes(test_pbf):
    from pyrosm import OSM
    from geopandas import GeoDataFrame
    osm = OSM(filepath=test_pbf)
    osm._read_pbf()
    nodes = osm._nodes_gdf

    assert isinstance(nodes, GeoDataFrame)

    # Required node columns
    node_cols = [
        'id', 'version', 'changeset', 'timestamp', 'lon', 'lat', 'tags'
    ]
    for col in node_cols:
        assert col in nodes.columns

    # Check shape
    assert nodes.shape == (14222, 8)
Esempio n. 6
0
def test_parsing_building_elements(test_pbf):
    from pyrosm import OSM
    from pyrosm.data_manager import get_osm_data
    osm = OSM(filepath=test_pbf)
    osm._read_pbf()
    custom_filter = {"building": True}
    nodes, ways, relation_ways, relations = get_osm_data(
        None,
        osm._way_records,
        osm._relations,
        osm.conf.tags.building,
        custom_filter,
        filter_type="keep")
    assert isinstance(ways, dict)

    # Required keys
    required = ['id', 'nodes']
    for col in required:
        assert col in ways.keys()

    # Test shape
    assert len(ways["id"]) == 2219
Esempio n. 7
0
def test_creating_building_geometries(test_pbf):
    from pyrosm import OSM
    from pyrosm.data_manager import get_osm_data
    from pyrosm.geometry import create_way_geometries
    from numpy import ndarray
    from shapely.geometry import Polygon

    osm = OSM(filepath=test_pbf)
    osm._read_pbf()
    custom_filter = {"building": True}
    nodes, ways, relation_ways, relations = get_osm_data(
        None,
        osm._way_records,
        osm._relations,
        osm.conf.tags.building,
        custom_filter,
        filter_type="keep")
    assert isinstance(ways, dict)

    geometries = create_way_geometries(osm._node_coordinates, ways)
    assert isinstance(geometries, ndarray)
    assert isinstance(geometries[0], Polygon)
    assert len(geometries) == len(ways["id"])