2

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?

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

2 Answers 2

2

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://rasterio.readthedocs.io/en/latest/topics/virtual-warping.html. It's easier to use than the less abstracted reproject() function.

1
  • 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
    Commented Jun 21, 2017 at 15:00
2

I had a similar problem:

rasterio.errors.CRSError: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.

After much testing and an error I arrived at the root of my problem: GDAL was installed through Anaconda while rasterio through pip

The solution: uninstall rasterio from pip and install it from Anaconda.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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