| | |
| | | public void setWaterHeight(LayerDto layer, List<String> files) { |
| | | int c = files.size(), step = files.size() / 10; |
| | | if (step < 1) step = 1; |
| | | double minx = Double.MAX_VALUE; |
| | | double miny = Double.MAX_VALUE; |
| | | double maxx = Double.MIN_VALUE; |
| | | double maxy = Double.MIN_VALUE; |
| | | for (int i = 0; i < c; i += step) { |
| | | Dataset ds = null; |
| | | try { |
| | |
| | | double[] mm = new double[2]; |
| | | ds.GetRasterBand(1).ComputeRasterMinMax(mm, 0); |
| | | layer.getWaters().setHeight(mm[0], mm[1]); |
| | | |
| | | double[] bbox = readTifBbox(ds); |
| | | double minLon = bbox[0]; |
| | | double maxLon = bbox[1]; |
| | | double minLat = bbox[2]; |
| | | double maxLat = bbox[3]; |
| | | if (minx > minLon) minx = minLon; |
| | | if (miny > minLat) miny = minLat; |
| | | if (maxx < maxLon) maxx = maxLon; |
| | | if (maxy < maxLat) maxy = maxLat; |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | |
| | | layer.getExtension().setDiffer(); |
| | | } |
| | | |
| | | private double[] readTifBbox(Dataset ds) { |
| | | // 1. 获取图像尺寸 |
| | | int width = ds.getRasterXSize(); |
| | | int height = ds.getRasterYSize(); |
| | | |
| | | // 2. 获取GeoTransform参数 |
| | | double[] geoTransform = new double[6]; |
| | | ds.GetGeoTransform(geoTransform); |
| | | |
| | | // 3. 解析GeoTransform参数(经纬度坐标) |
| | | double originLon = geoTransform[0]; // 左上角经度 |
| | | double originLat = geoTransform[3]; // 左上角纬度 |
| | | double pixelWidth = geoTransform[1]; // 经度方向分辨率(度/像素) |
| | | double pixelHeight = geoTransform[5]; // 纬度方向分辨率(度/像素,通常为负) |
| | | |
| | | // 4. 计算四至范围(经纬度) |
| | | double minLon = Math.min(originLon, originLon + width * pixelWidth); |
| | | double maxLon = Math.max(originLon, originLon + width * pixelWidth); |
| | | double minLat = Math.min(originLat, originLat + height * pixelHeight); |
| | | double maxLat = Math.max(originLat, originLat + height * pixelHeight); |
| | | return new double[] {minLon, maxLon, minLat, maxLat}; |
| | | } |
| | | |
| | | public void processWaters(ResultDto dto, List<String> files, LayerDto layer) { |
| | | for (int i = 0, c = files.size(); i < c; i++) { |
| | | Dataset ds = null; |