TransWikia.com

Rasterio symbology

Geographic Information Systems Asked by Ric_02 on December 23, 2020

I am having a problem with a raster dataset. I am trying to use a symbology for a continuous raster type but the result is as shown in the image.
The code is:

import os
import numpy as np
import pandas as pd
import geopandas as gpd
import rasterio
import matplotlib as mpl
import matplotlib.pyplot as plt

from matplotlib.patches import Patch
from matplotlib.colors import BoundaryNorm
from matplotlib import rcParams, cycler
from rasterio.plot import show
from rasterio.plot import show_hist
from rasterio.warp import calculate_default_transform, reproject, Resampling
from collections import OrderedDict


%matplotlib inline

## we read a shapefile and convert it to dataframe, set crs.
shp_europeLowres = "assignment3_data/europe_lowres.shp"

df_europeLowres = gpd.read_file(shp_europeLowres)
df_europeLowres.to_crs(epsg=4326)

##loading and reading a raster

gpcc_dataset_84 = rasterio.open("assignment3_data/gpcc_precip_2018_WGS84.tif")

print(gpcc_dataset_84.profile)


fig,axr = plt.subplots(1,1, figsize=(31,9)) ## this is a unique frame to put your map. 

show((gpcc_dataset_84, 1), transform=gpcc_dataset_84.transform, ax=axr, cmap='twilight', title='The WORLD !!')

df_europeLowres.plot(ax=axr, facecolor="none", edgecolor='black', lw=1)

I would like to know how to get rid of those NAs if it is necessary to perform the symbology ramp colour in python.
I load this raster on QGIS and I can see the values of the cells.
enter image description here

One Answer

I have just seen the error. I hope this solution can help someone with the same problem.

In the following line:

show((gpcc_dataset_84, 1), transform=gpcc_dataset_84.transform, ax=axr, cmap='twilight', title='The WORLD !!')

it should be:

show(gpcc_dataset_84, transform=gpcc_dataset_84.transform, ax=axr, cmap='twilight', title='The WORLD !!')

Because we are reading a raster dataset, not a band.

Answered by Ric_02 on December 23, 2020

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