1

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)

1 Answer 1

0

Use gdal_calc to reclassify your raster. Turn those values that you do not want into no data values and keep the land values you want. See this link And this link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.