1

I am trying to reproject on python 2.7 a Landsat8 image from UTM 19N to UTM 18S using rasterio, reading the docs I found and example on the documentation and just change the input, output file and dst_CRS:

import numpy as np
import rasterio
from rasterio.warp import calculate_default_transform, reproject, RESAMPLING

INPUT_raster_1 = "D:\Minam\LC08_L1TP_005063_20170528_20170528_01_RT\LC08_L1TP_005063_20170528_20170528_01_RT_B5.tif"
dst_crs ='EPSG:32718' #output reprojection

with rasterio.open("D:\Minam\LC08_L1TP_005063_20170528_20170528_01_RT\LC08_L1TP_005063_20170528_20170528_01_RT_B5.tif") as src:
    affine, width, height = calculate_default_transform(
        src.crs, dst_crs, src.width, src.height, *src.bounds)
    kwargs = src.meta.copy()
    kwargs.update({
        'crs': dst_crs,
        'transform': affine,
        'affine': affine,
        'width': width,
        'height': height
    })

    with rasterio.open('D:\Minam\wgs84.tif', 'w', **kwargs) as dst:
        for i in range(1, src.count + 1):
            reproject(
                source=rasterio.band(src, i),
                destination=rasterio.band(dst, i),
                src_transform=src.affine,
                src_crs=src.crs,
                dst_transform=affine,
                dst_crs=dst_crs,
                resampling=RESAMPLING.nearest)

The first problem is that there is no module RESAMPLING on library, then this when reading the dst_crs:

rasterio.errors.CRSError: Invalid CRS: 'EPSG:32718'

But that is the epsg to utm 18S. How do I fix it?

  • 1
    Documentation actually has "dst_crs = {'init': 'EPSG:3857'}". Try changing to that format with 'EPSG:32718'. – mkennedy Jun 14 '17 at 19:15
  • still the same error: 'rasterio.errors.CRSError: Invalid CRS: CRS({'init': 'EPSG:3857'})' or EPSG:32718 – Ivan Jun 14 '17 at 19:33
1

The 'invalid CRS' error indicates to me that GDAL can't find an EPSG database file. See https://trac.osgeo.org/gdal/wiki/FAQInstallationAndBuilding#WhatisGDAL_DATAenvironmentvariable for how to set the GDAL_DATA environment variable.

For warping, I suggest this new Rasterio feature (based on a well-known GDAL feature): https://mapbox.github.io/rasterio/topics/virtual-warping.html. It's easier to use than the less abstracted reproject() function.

  • You were right, on this machine someone was previously installed GDAL for windows but the environment variable was wrong configurated, re-did it and try reprojecting (but using GDAL) check answer here – Ivan Jun 21 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.