コード例 #1
0
def training_features(case_study, year, transform, width, height):
    """Extract and rasterize training data from the OSM database."""
    aoi = case_study.aoi_latlon
    crs = case_study.crs

    db = osm.OSMDatabase(DB_NAME, DB_USER, DB_PASS, DB_HOST)
    buildings = training.buildings(db,
                                   aoi,
                                   crs,
                                   transform,
                                   width,
                                   height,
                                   min_coverage=0.25)
    blocks = training.blocks(db,
                             aoi,
                             crs,
                             transform,
                             width,
                             height,
                             max_surface=30000)
    nonbuilt = training.nonbuilt(db, aoi, crs, transform, width, height)
    remote = training.remote(db,
                             aoi,
                             crs,
                             transform,
                             width,
                             height,
                             min_distance=250)

    return buildings, blocks, nonbuilt, remote
コード例 #2
0
def water_mask(case_study, crs, transform, width, height):
    """Extract water mask from OSM database (water bodies + oceans)."""
    db = osm.OSMDatabase(DB_NAME, DB_USER, DB_PASS, DB_HOST)
    polygons = db.water(case_study.aoi_latlon)
    geoms = [feature['geometry'] for feature in polygons]
    geoms = [transform_geom(WGS84, crs, geom) for geom in geoms]
    if len(geoms) == 0:
        return np.zeros(shape=(height, width), dtype=np.bool)
    water = rasterize(shapes=geoms,
                      out_shape=(height, width),
                      transform=transform,
                      dtype=np.uint8).astype(np.bool)
    db.connection.close()
    return water
コード例 #3
0
def update_osm_database(case_study):
    """Import OSM data into the PostGIS db for a given case study.
    Depends on `<DATA_DIR>/input/africa-latest.osm.pbf` and the
    osmium software.

    Parameters
    ----------
    case_study : maupp.CaseStudy
        Case study of interest.
    """
    db = osm.OSMDatabase(DB_NAME, DB_USER, DB_PASS, DB_HOST)
    main_datafile = os.path.join(DATA_DIR, 'input', 'africa-latest.osm.pbf')
    dst_datafile = os.path.join(case_study.inputdir, 'osm',
                                case_study.id + '.osm.pbf')
    os.makedirs(os.path.dirname(dst_datafile), exist_ok=True)
    if not db.data_in_aoi(case_study.aoi_latlon.wkt):
        if os.path.isfile(dst_datafile):
            os.remove(dst_datafile)
        osm.geoextract_osmpbf(main_datafile, dst_datafile,
                              case_study.aoi_latlon.bounds)
        db.import_data(dst_datafile)
    db.connection.close()
    return True
コード例 #4
0
def ocean_table():
    """Check that oceans and seas have been added to the OSM db."""
    db = osm.OSMDatabase(DB_NAME, DB_USER, DB_PASS, DB_HOST)
    osm.import_oceans(db.connection)
    return True