Ejemplo n.º 1
0
def test_return_tile():

    address = spacenetPath

    with rasterio.open(address) as src:

        wgs_bounds = utils.get_wgs84_bounds(src)
        utm_crs = utils.calculate_UTM_crs(wgs_bounds)
        utm_bounds = utils.get_utm_bounds(src, utm_crs)

        cells_list = main.calculate_analysis_grid(
            utm_bounds,
            stride_size_meters=stride_size_meters,
            cell_size_meters=cell_size_meters)

        random_cell = random.choice(cells_list[0])
        ll_x, ll_y, ur_x, ur_y = random_cell
        print(random_cell)
        tile, mask, window, window_transform = main.tile_utm(
            src,
            ll_x,
            ll_y,
            ur_x,
            ur_y,
            indexes=None,
            tilesize=tile_size_pixels,
            nodata=None,
            alpha=None,
            dst_crs=utm_crs)

        print(np.shape(tile))
        assert np.shape(tile) == (8, tile_size_pixels, tile_size_pixels)
Ejemplo n.º 2
0
def test_calculate_utm_epsg():

    wgs_bounds = utils.get_wgs84_bounds(ADDRESS)
    print(wgs_bounds)
    utm_crs = utils.calculate_UTM_crs(wgs_bounds)
    print(utm_crs)
    assert utm_crs == '+proj=utm +zone=13 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
Ejemplo n.º 3
0
def test_return_vector_tile():
    utm_crs = utils.calculate_UTM_crs(
        [-115.30170, 36.15604, -115.30170, 36.15604])

    gdf = vector_utils.read_vector_file(geojsonPath)
    gdf.head()
    print(utm_crs)
    gdf = vector_utils.transformToUTM(gdf, utm_crs=utm_crs)

    utmX, utmY = 658029, 4006947
    ll_x = utmX
    ur_x = utmX + 500
    ll_y = utmY
    ur_y = utmY + 500
    stride_size_meters = 300
    cell_size_meters = 400
    tile_size_pixels = 1600

    small_gdf = vector_utils.vector_tile_utm(
        gdf, tile_bounds=[ll_x, ll_y, ur_x, ur_y])

    img = vector_utils.rasterize_gdf(small_gdf,
                                     src_shape=(tile_size_pixels,
                                                tile_size_pixels))

    print(img.shape)

    assert img.shape[0] == 1600
Ejemplo n.º 4
0
def get_processing_details(
    rasterPath,
    smallExample=False,
    dstkwargs={
        "nodata": 0,
        "interleave": "pixel",
        "tiled": True,
        "blockxsize": 512,
        "blockysize": 512,
        "compress": "LZW"
    }):
    with rasterio.open(rasterPath) as src:

        # Get Lat, Lon bounds of the Raster (src)
        wgs_bounds = utils.get_wgs84_bounds(src)

        # Use Lat, Lon location of Image to get UTM Zone/ UTM projection
        utm_crs = utils.calculate_UTM_crs(wgs_bounds)

        # Calculate Raster bounds in UTM coordinates
        utm_bounds = utils.get_utm_bounds(src, utm_crs)

        vrt_profile = utils.get_utm_vrt_profile(
            src,
            crs=utm_crs,
        )

        dst_profile = vrt_profile
        dst_profile.update({
            'count': 1,
            'dtype': rasterio.uint8,
            'driver': "GTiff",
        })
        # update for CogStandard
        dst_profile.update(dstkwargs)

    # open s3 Location
    rasterBounds = geometry.box(*utm_bounds)

    if smallExample:
        rasterBounds = geometry.box(*rasterBounds.centroid.buffer(1000).bounds)

    return rasterBounds, dst_profile
Ejemplo n.º 5
0
def test_grid_creation():

    address = spacenetPath

    with rasterio.open(address) as src:

        wgs_bounds = utils.get_wgs84_bounds(src)
        utm_EPSG = utils.calculate_UTM_crs(wgs_bounds)
        utm_bounds = utils.get_utm_bounds(src, utm_EPSG)
        print(utm_bounds)
        cells_list_dict = main.calculate_analysis_grid(
            utm_bounds,
            stride_size_meters=stride_size_meters,
            cell_size_meters=cell_size_meters)
        print(len(cells_list_dict))

    assert len(cells_list_dict[0][0]) == 4
    assert ((cells_list_dict[0][0][2] - cells_list_dict[0][0][0]),
            (cells_list_dict[0][0][3] -
             cells_list_dict[0][0][1])) == (cell_size_meters, cell_size_meters)
    assert (cells_list_dict[0][1][1] -
            cells_list_dict[0][0][1]) == stride_size_meters
    assert len(cells_list_dict[0]) == 2491
Ejemplo n.º 6
0
os.environ['CURL_CA_BUNDLE'] = '/etc/ssl/certs/ca-certificates.crt'

## give location to SpaceNet 8-Band PanSharpened Geotiff on s3

#spacenetPath = "s3://spacenet-dataset/AOI_2_Vegas/srcData/rasterData/AOI_2_Vegas_MUL-PanSharpen_Cloud.tif"
spacenetPath = "/home/dlindenbaum/datastorage/spacenet_sample/AOI_2_Vegas_MUL-PanSharpen_Cloud.tif"
osm_labels_path = "./tests/fixtures/my-bucket/spacenet_test/las-vegas_nevada_osm_buildings.geojson"

## Prep files for UTM
with rasterio.open(spacenetPath) as src:

    # Get Lat, Lon bounds of the Raster (src)
    wgs_bounds = utils.get_wgs84_bounds(src)

    # Use Lat, Lon location of Image to get UTM Zone/ UTM projection
    utm_crs = utils.calculate_UTM_crs(wgs_bounds)

    # Calculate Raster bounds in UTM coordinates
    utm_bounds = utils.get_utm_bounds(src, utm_crs)

## read vector file
gdf = vector_utils.read_vector_file(osm_labels_path)
gdf.head()
gdf_utm = vector_utils.transformToUTM(gdf, utm_crs=utm_crs)

# open s3 Location

# Each grid starting point will be spaced 400m apart
stride_size_meters = 400

# Each grid cell will be 400m on a side
Ejemplo n.º 7
0
def test_return_tile_full():

    ## Set for specific tile in Las Vegas
    utm_crs = utils.calculate_UTM_crs(
        [-115.30170, 36.15604, -115.30170, 36.15604])
    gdf = vector_utils.read_vector_file(geojsonPath)
    gdf.head()
    gdf = vector_utils.transformToUTM(gdf, utm_crs=utm_crs)

    utmX, utmY = 658029, 4006947
    ll_x = utmX
    ur_x = utmX + 500
    ll_y = utmY
    ur_y = utmY + 500
    stride_size_meters = 300
    cell_size_meters = 400
    tile_size_pixels = 1600

    address = spacenetPath

    with rasterio.open(address) as src:

        src_profile = src.profile

        tile, mask, window, window_transform = main.tile_utm(
            src,
            ll_x,
            ll_y,
            ur_x,
            ur_y,
            indexes=None,
            tilesize=tile_size_pixels,
            nodata=None,
            alpha=None,
            dst_crs=utm_crs)

        print(np.shape(tile))
        assert np.shape(tile) == (8, tile_size_pixels, tile_size_pixels)

        small_gdf = vector_utils.vector_tile_utm(
            gdf, tile_bounds=[ll_x, ll_y, ur_x, ur_y])
        print(small_gdf.shape)
        small_gdf.to_file(os.path.join(PREFIX, "testTiff_Label.geojson"),
                          driver='GeoJSON')
        img = vector_utils.rasterize_gdf(
            small_gdf,
            src_shape=(tile_size_pixels, tile_size_pixels),
            src_transform=window_transform,
        )
        print("Label Count Burn {}:".format(np.sum(img)))
        assert img.shape == (tile_size_pixels, tile_size_pixels)

        dst_profile = src_profile
        dst_profile.update({
            'transform': window_transform,
            'crs': utm_crs,
            'width': tile_size_pixels,
            'height': tile_size_pixels,
            'count': 1,
            'dtype': rasterio.uint8
        })

        with rasterio.open(os.path.join(PREFIX, "testTiff_Label.tif"), 'w',
                           **dst_profile) as dst:

            dst.write(img, indexes=1)

        dst_profile = src_profile
        dst_profile.update({
            'transform': window_transform,
            'crs': utm_crs,
            'width': tile_size_pixels,
            'height': tile_size_pixels,
            'count': 8,
            'dtype': rasterio.uint16
        })

        with rasterio.open(os.path.join(PREFIX, "testTiff_Image.tif"), 'w',
                           **dst_profile) as dst:

            dst.write(tile)