I have downloaded MODIS land use land cover data.The key name of the data product is MCD12C1.Now I want to plot/visualize different land use land cover data on map using python.`
import numpy as np
import pandas as pd
import rioxarray
import rasterio as rio
from osgeo import gdal
import earthpy as et
import earthpy.spatial as es
import earthpy.plot as ep
title='c:/MCD12C1.A2022001.061.2023244164746'
all_bands=[]
with rio.open(f'{title}.HDF') as dataset:
hdf4_meta = dataset.meta
crs = dataset.read_crs()
for layer_name in [name for name in dataset.subdatasets]:
print(layer_name)
with rio.open(layer_name) as subdataset:
modis_meta = subdataset.profile
all_bands.append(subdataset.read(1))
I have written the above code.After this how to proceed ? `
I guess your problem is that the data is quite large and your script will take ages to finish reading... what you want is to open the file lazily and then only select what you really need!
I'd suggest that you have a look at rioxarray (the rasterio-extension for
xarray) and load the data withchunks=Trueso that the file is loaded as a lazydaskdataset.Then you can easily pre-select the data and only load what you really need.
Something like this should do the job:
Once you have your dataset loaded, you can plot it with EOmaps like this:
I use
m.set_shape.raster(maxsize=1e5)to visualize the data as a 2D raster, pre-aggregated to ~1e5 datapoints (in total it's ~26 million) prior to plotting.