Rasters
Rasters
Rasters
May 2, 2024
[16]: os.getcwd()
[16]: 'C:\\Users\\Aurora\\Desktop\\Gabriel\\PYTHON\\Jupyter_PyGis'
[26]: raster_base.name
[26]: 'C:/Users/Aurora/Desktop/Gabriel/PYTHON/Jupyter_PyGis/dados/cbers.tif'
[27]: raster_base.mode
[27]: 'r'
[50]: raster_base.count
[50]: 4
[28]: raster_base.closed
[28]: False
[51]: raster_base.close()
[53]: dst.closed
1
[53]: True
[60]: profile
[60]: {'driver': 'GTiff', 'dtype': 'float32', 'nodata': None, 'width': 1929, 'height':
1943, 'count': 4, 'crs': CRS.from_epsg(32721), 'transform': Affine(8.0, 0.0,
734856.0,
0.0, -8.0, 7189156.0), 'blockysize': 1, 'tiled': False, 'interleave':
'pixel'}
[62]: profile['count'] = 1
[63]: profile
[63]: {'driver': 'GTiff', 'dtype': 'float32', 'nodata': None, 'width': 1929, 'height':
1943, 'count': 1, 'crs': CRS.from_epsg(32721), 'transform': Affine(8.0, 0.0,
734856.0,
0.0, -8.0, 7189156.0), 'blockysize': 1, 'tiled': False, 'interleave':
'pixel'}
[93]: plt.figure(figsize=(5,5))
show(band1, cmap='gray', transform = profile['transform'])
2
[93]: <Axes: >
3
[92]: result = band1*band2
show(result, cmap='grey', transform = profile['transform'], title='Result')
4
[95]: # Função para normalizar valor
def normalize(array):
'''Normaliza variavel numpy em escala de 0.0 a 1.0'''
array_min, array_max = array.min(), array.max()
return((array - array_min)/(array_max - array_min))
5
[107]: plt.figure(figsize=(21,9))
show([r,g,b], transform=profile['transform'])
def normalize(array):
6
'''Normaliza variavel numpy em escala de 0.0 a 1.0'''
array_min, array_max = array.min(), array.max()
def cbers_raster(raster):
# C:\\Users\\Aurora\\Desktop\\Gabriel\\PYTHON\\Jupyter_PyGis\\dados\\cbers.tif␣
↪Pois o notebook não está na mesma pasta
def cbers_index():
band1, band2, band3, band4, profile = cbers_raster(raster)
# Normalizar os Dados
ir = normalize(band4)
r = normalize(band3)
g = normalize(band2)
b = normalize(band1)
# Criando Indíces
ndvi = (ir-r)/(ir+r) # Vigor da Vegetação
ndwi = (g-ir)/(g+ir) # Massas D'água
def plot_cbers():
ndvi, ndwi, profile = cbers_index()
return
7
[31]: raster = 'C:
↪\\Users\\Aurora\\Desktop\\Gabriel\\PYTHON\\Jupyter_PyGis\\dados\\cbers.tif'
plot_cbers()
[ ]:
[ ]:
[ ]:
[ ]:
[ ]: