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)

Taras
  • 32,823
  • 4
  • 66
  • 137
hashalluring
  • 119
  • 12

1 Answers1

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

GBG
  • 9,737
  • 1
  • 15
  • 44