| | |
| | | import com.se.nsl.helper.WebHelper; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.gdal.Band; |
| | | import org.gdal.gdal.Dataset; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconstConstants; |
| | |
| | | |
| | | String terrainFile = inPath + File.separator + config.getTerrainFile(); |
| | | Dataset dsDem = gdal.Open(config.getSourceDem(), gdalconstConstants.GA_ReadOnly); |
| | | ComHelper.Resample(dsDem, null, terrainFile, wkt, null, null); |
| | | ComHelper.Resample(dsDem, null, terrainFile, null, wkt, null, null); |
| | | dsDem.delete(); |
| | | |
| | | String landuseFile = inPath + File.separator + config.getLanduseFile(); |
| | | Dataset dsLanduse = gdal.Open(config.getSourceLanduse(), gdalconstConstants.GA_ReadOnly); |
| | | ComHelper.Resample(dsLanduse, null, landuseFile, wkt, null, null); |
| | | ComHelper.Resample(dsLanduse, null, landuseFile, null, wkt, null, null); |
| | | dsLanduse.delete(); |
| | | } |
| | | |
| | | public void updateTif(Simu simu, SimuData data2) throws IOException { |
| | | Dataset ds = gdal.Open(config.getSourceLanduse(), gdalconstConstants.GA_Update); // 以读写模式打开TIFF文件 |
| | | |
| | | Band band = ds.GetRasterBand(1); |
| | | if (band.GetRasterDataType() != gdalconstConstants.GDT_Byte) { |
| | | System.err.println("错误:非Byte类型数据"); |
| | | ds.delete(); |
| | | return; |
| | | } |
| | | |
| | | int width = band.getXSize(); |
| | | int height = band.getYSize(); |
| | | |
| | | // 读取Byte类型数据 |
| | | byte[] data = new byte[width * height]; |
| | | band.ReadRaster(0, 0, width, height, data); |
| | | |
| | | // 替换0值为8(注意Java的byte是有符号的,需处理0-255范围) |
| | | for (int i = 0; i < data.length; i++) { |
| | | if ((data[i] & 0xFF) == 0) { // 无符号比较 |
| | | data[i] = (byte) 8; |
| | | } |
| | | } |
| | | |
| | | band.WriteRaster(0, 0, width, height, data); // 写回数据并保存 |
| | | band.SetNoDataValue(8.0); // 设置新Nodata值 |
| | | band.FlushCache(); // 强制写入更改 |
| | | ds.delete(); |
| | | } |
| | | |
| | | private void createDir(String path) { |
| | | File f = new File(path); |
| | | if (f.exists() && f.isDirectory()) { |