0

I am trying to calculate summary statistics for a raster file. I am encountering a problem when loading my raster into Python.

When I load the raster and I plot it, it is flipped 180 degrees. This means it is upside down.

When the raster is loaded into QGIS or ArcMap is properly displayed. How can I proceed?

import os
import sys
import glob
import rasterio
import gdal
from rasterio.plot import show
from rasterio.transform import Affine
import networkx as nx
import geopandas as gpd
import osmnx as ox
import matplotlib.pyplot as plt
from rasterstats import zonal_stats

os.getcwd()

path = "path_to_data"
gis = "path_to_vector"

raster = "path_to_raster**"

raster_yearly_path = [f for f in glob.glob(raster + '*ppty.tif', recursive=True)]  

raster_yearly = []

for raster in raster_yearly_path:
    local = rasterio.open(raster)
    raster_yearly.append(local)

ax = show(raster_yearly[0])

Inverted raster

I cannot move forward since the basins will not be in the proper extent. Please check the image below. I need to process more than 500 rasters. This is why I am using Python.

Correc raster

  • 1
    It's not clear how you could generate this outcome (code necessay), but how does the order of row processing impact summary statistics? – Vince Mar 26 at 6:56
  • What do you mean when you plot it in Python? Are you using some Python library to plot your raster? If so, this library may not recognize the world file associated with your data. It is this world file that is allowing a GIS to properly display your data. – GBG Mar 26 at 14:40
  • I have added some comments and more information. – Daniel Mar 26 at 14:56
  • 1
    your raster is fine, you're just plotting it wrong. pyplot.imshow(<array>, origin='lower') – Paul H Mar 26 at 23:53

Your Answer

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

Browse other questions tagged or ask your own question.