I am a newbie in programming and wanted to ask if someone could help me with example of loading/reading multiple rasters using for loop (or maybe another alternatives to deal with multiple files?). Basically, it loads several rasters with gdal, then plot and export the map as html file using folium. Here is the code :
import gdal
import folium
#poland dataset
pol = gdal.Open('ISG/POLAND_KTH-PL-GEOID2015_15_G_20160729.isg')
#Get coordinates, cols and rows
polgeotransform = pol.GetGeoTransform()
polcols = pol.RasterXSize
polrows = pol.RasterYSize
#Get extent
polxmin=polgeotransform[0]
polymax=polgeotransform[3]
polxmax=polxmin+polcolspolgeotransform[1]
polymin=polymax+polrowspolgeotransform[5]
#Get Central point
polcenterx=(polxmin+polxmax)/2
polcentery=(polymin+polymax)/2
#Raster convert to array
polbands = pol.RasterCount
polband = pol.GetRasterBand(1)
poldataset= polband.ReadAsArray(0,0,polcols,polrows)
poldataimage=poldataset
poldataimage[poldataimage[:,:]==-340282346638528859811704183484516925440.000]=0
#-------------------------------------------------------------------------
#netherlands dataset
nl = gdal.Open('ISG/NLGEO218_20191011.isg')
#Get coordinates, cols and rows
nlgeotransform = nl.GetGeoTransform()
nlcols = nl.RasterXSize
nlrows = nl.RasterYSize
#Get extent
nlxmin=nlgeotransform[0]
nlymax=nlgeotransform[3]
nlxmax=nlxmin+nlcolsnlgeotransform[1]
nlymin=nlymax+nlrowsnlgeotransform[5]
#Get Central point
nlcenterx=(nlxmin+nlxmax)/2
nlcentery=(nlymin+nlymax)/2
#Raster convert to array
nlbands = nl.RasterCount
nlband = nl.GetRasterBand(1)
nldataset= nlband.ReadAsArray(0,0,nlcols,nlrows)
nldataimage=nldataset
nldataimage[nldataimage[:,:]==-340282346638528859811704183484516925440.000]=0
#-------------------------------------------------------------------------
#Visualization in folium
map= folium.Map(location=[centery, centerx], zoom_start=3)
folium.TileLayer('Stamen Terrain').add_to(map)
folium.TileLayer('cartodbpositron').add_to(map)
#--------------------------------------------------------------------------
#geoid layers visualization
#poland
pol = folium.raster_layers.ImageOverlay(
image=poldataimage,
bounds=[[polymin, polxmin], [polymax, polxmax]],
opacity=1,
show=False,
).add_to(map)
#netherlands
nl = folium.raster_layers.ImageOverlay(
image=nldataimage,
bounds=[[nlymin, nlxmin], [nlymax, nlxmax]],
opacity=1,
show=False,
).add_to(map)
add name to the layers
pol.layer_name = 'Poland'
nl.layer_name = 'Netherlands'
folium.LayerControl().add_to(map)
#Save to html
map.save('html/plotISG.html')
m = folium.Map()
html_string = m.get_root().render()