| | |
| | | WarpOptions warpOptions = new WarpOptions(vector); |
| | | |
| | | Dataset destDs = gdal.Warp(dest, new Dataset[]{ds}, warpOptions); |
| | | updateLayerExtension(destDs, layer); |
| | | destDs.delete(); |
| | | } |
| | | |
| | | private static void updateLayerExtension(Dataset ds, LayerDto layer) { |
| | | double[] bbox = readTifBbox(ds); |
| | | double minLon = bbox[0]; |
| | | double maxLon = bbox[1]; |
| | | double minLat = bbox[2]; |
| | | double maxLat = bbox[3]; |
| | | ExtensionDto extension = layer.getExtension(); |
| | | double minx = extension.getMinx(); |
| | | double miny = extension.getMiny(); |
| | | double maxx = extension.getMaxx(); |
| | | double maxy = extension.getMaxy(); |
| | | if (minx > minLon) extension.setMinx(minLon); |
| | | if (miny > minLat) extension.setMiny(minLat); |
| | | if (maxx < maxLon) extension.setMaxx(maxLon); |
| | | if (maxy < maxLat) extension.setMaxy(maxLat); |
| | | } |
| | | |
| | | private static 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 static BuildingDto intersects(ResultDto dto, double x, double y) { |
| | | Geometry p = new Geometry(ogr.wkbPoint); |
| | | p.AddPoint_2D(x, y); |