TransWikia.com

Rasterio reprojection, changing pixel size: results in crazy pixel values

Geographic Information Systems Asked on July 14, 2021

I’m trying to project a geotiff with 789x789m pixel size to 100mx100m using another geotiff as a template. Everything seems to work except that the output pixel values, shown when I open the file in QGIS, are 1.79769e+308 to -1.79769e+308 (inputs are between 890-1776). I’m not changing the CRS…and the dimensions, origin, pixel size and extent of the output file look right. What am I doing wrong? I’m very much a Python beginner so it’s probably very simple.

from natsort import natsorted
import os
import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling

template = file_dir+'/NG_boundary.tif'

list_test_files=[]
names_test=[]
dst_crs = 'EPSG:32554'

for root, dirs, files in os.walk(file_dir+"/test"):
    for file in files:
        if file.endswith('.tif') and "boundary" not in file and "projected" not in file:
            list_test_files.append(file_dir+"/test/"+file)
            name = file.replace(".tif", "")
            names_test.append(name)
            names_test = natsorted(names_test, key=lambda y: y.lower())
            with rasterio.open(template) as src:
                transform, 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': transform,
                    'width': width,
                    'height': height
                })
                print('source', src.profile)
                with rasterio.open(file_dir + '/test/%s_projected.tif' % name, 'w', **kwargs) as dst:
                    for i in range(1, dst.count + 1):
                        reproject(
                            source=rasterio.band(dst, i),
                            destination=rasterio.band(dst, i),
                            src_transform=src.transform,
                            src_crs=src.crs,
                            dst_transform=transform,
                            dst_crs=dst_crs,
                            resampling=Resampling.nearest)
                    print('output', dst.profile)
                print(names_test)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP