Skip to content

Instantly share code, notes, and snippets.

@underchemist
Created November 5, 2020 02:25
Show Gist options
  • Save underchemist/8e57d222e472b8a5c909843f80a7a176 to your computer and use it in GitHub Desktop.
Save underchemist/8e57d222e472b8a5c909843f80a7a176 to your computer and use it in GitHub Desktop.
rasterio warp with rpcs example
"""
RPC_DEM_SRS only used in GDAL >= 3.2.0, otherwise ignored
"""
import rasterio
import rasterio.warp
from rasterio import logging
logging.basicConfig(filename='rasterio.log', level=logging.DEBUG)
with rasterio.Env(CPL_DEBUG='ON', PROJ_DEBUG='3') as env: # maybe still set CPL_DEBUG and PROJ_DEBUG as env var?
with rasterio.open('rpc.tif') as src:
arr, transform = rasterio.warp.reproject(
rasterio.band(src, src.indexes),
src_crs="EPSG:4326",
rpcs=src.rpcs,
dst_crs="EPSG:4326",
RPC_DEM="vancouver-dem-downsampled.tif",
RPC_DEM_SRS="EPSG:4326+5773"
)
with rasterio.open('rpc-warped-rasterio.tif', mode='w', transform=transform, crs="EPSG:4326", dtype=src.dtypes[0], count=arr.shape[0], height=arr.shape[1], width=arr.shape[2]) as dst:
dst.write(arr, src.indexes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment