Exemplo 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)
Exemplo 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'
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
import os
from tqdm import tqdm
# Setting Certificate Location for Ubuntu/Mac OS locations (Rasterio looks for certs in centos locations)
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