Skip to main content
Post Undeleted by wingnut
Found a better way, tested it, summarised it.
Source Link
wingnut
  • 2.1k
  • 5
  • 10

Create the initial raster fromThis Page seems to have the Numpy array in Python using rasterio. It should be included with QGIS. If not, just install itanswer you are looking for.

See example at You need to use Rasterio - Creating datarasterio.warp.calculate_default_transform()

  1. load and reshape the Numpy array

    Create your raster in EPSG:4326 as you have already done

  2. create the raster with rasterio

    reproject according to the method in the link (just tested it - it works)

     from rasterio.warp import calculate_default_transform, reproject, Resampling
    
     filename = 'my_4326_file.tif'
     with rasterio.open(filename) 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
         })
         outfilename = '/Users/zoid/Desktop/my_32755_file.tif'
    
         with rasterio.open(outfilename, '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.transform,
                     src_crs=src.crs,
                     dst_transform=transform,
                     dst_crs=dst_crs,
                     resampling=Resampling.lanczos)
    

This should be easierresulted in a transformed raster that matches the untransformed one. Rasterio can also handle reprojection

Create the initial raster from the Numpy array in Python using rasterio. It should be included with QGIS. If not, just install it.

See example at Rasterio - Creating data

  1. load and reshape the Numpy array
  2. create the raster with rasterio

This should be easier. Rasterio can also handle reprojection

This Page seems to have the answer you are looking for. You need to use rasterio.warp.calculate_default_transform()

  1. Create your raster in EPSG:4326 as you have already done

  2. reproject according to the method in the link (just tested it - it works)

     from rasterio.warp import calculate_default_transform, reproject, Resampling
    
     filename = 'my_4326_file.tif'
     with rasterio.open(filename) 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
         })
         outfilename = '/Users/zoid/Desktop/my_32755_file.tif'
    
         with rasterio.open(outfilename, '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.transform,
                     src_crs=src.crs,
                     dst_transform=transform,
                     dst_crs=dst_crs,
                     resampling=Resampling.lanczos)
    

This resulted in a transformed raster that matches the untransformed one.

Post Deleted by wingnut
Source Link
wingnut
  • 2.1k
  • 5
  • 10

Create the initial raster from the Numpy array in Python using rasterio. It should be included with QGIS. If not, just install it.

See example at Rasterio - Creating data

  1. load and reshape the Numpy array
  2. create the raster with rasterio

This should be easier. Rasterio can also handle reprojection