I have a svm predicted model which when applied on raster images classifies the LULC of land and writes the output to raster file. I want to use only the Land used part out of the output raster image. Any leads on this.
Below is the code used for svm prediction:
bands_data = np.dstack(bands_data)
bands_data = np.nan_to_num(bands_data)
rows, cols, n_bands = bands_data.shape
n_samples = rows * cols
flat_pixels = bands_data.reshape((n_samples, n_bands))
r = clf.predict(flat_pixels)
result = np.array([int(i) for i in r])
classification = result.reshape((rows,cols))
def write_geotiff(fname, data, geo_transform, projection):
"""Create a GeoTIFF file with the given data."""
driver = gdal.GetDriverByName('GTiff')
rows, cols = data.shape
dataset = driver.Create(fname, cols, rows, 1, gdal.GDT_Float32)
dataset.SetProjection(projection)
band = dataset.GetRasterBand(1)
band.WriteArray(data[np.where(data == 1)])
dataset = None #Close the file
print("done")
output_file = fname
write_geotiff(output_file,classification, gt, proj)