| | |
| | | import org.gdal.gdal.Dataset; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconst; |
| | | import org.gdal.ogr.*; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取图层 * |
| | | */ |
| | | public Layer getLayer(String serviceName) { |
| | | Layer layer = new Layer(); |
| | | layer.setVersion(config.getVer()); |
| | | layer.setDuration(new Duration(1719812810225L, 1719812810225L)); |
| | | layer.setExtension(new Extension(2.11062743358, 0.53812160220, 2.11070827834, 0.53819799453, 1.151, 38.83)); |
| | | |
| | | List<Integer[]> sizes = new ArrayList<>(); |
| | | sizes.add(new Integer[]{64, 64}); |
| | | sizes.add(new Integer[]{128, 128}); |
| | | sizes.add(new Integer[]{256, 256}); |
| | | sizes.add(new Integer[]{512, 512}); |
| | | sizes.add(new Integer[]{1024, 1024}); |
| | | sizes.add(new Integer[]{2048, 2048}); |
| | | layer.setTerrain(new Terrain(sizes)); |
| | | |
| | | List<Long> data = new ArrayList<>(Arrays.asList(1719812812225L, 1719812812225L, 1719812812225L, 1719812812225L, 1719812812225L, 1719812812225L)); |
| | | layer.setWaters(new Water(data)); |
| | | |
| | | return layer; |
| | | } |
| | | |
| | | /** |
| | | * 根据坐标查询积水深度:gdalconst.GA_Update |
| | | */ |
| | | public Double getWaterHeight(SimuPo simu, double x, double y, Long timestamp) { |
| | | String filePath = config.getOutPath() + File.separator + simu.getServiceName() + File.separator + "waters" |
| | | + File.separator + timestamp + File.separator + "water.tif"; |
| | | if (!FileUtil.exist(filePath)) return null; |
| | | |
| | | Dataset ds = null; |
| | | try { |
| | |
| | | return !Double.isNaN(val) && val > Integer.MIN_VALUE; |
| | | } |
| | | |
| | | public Double getWaterArea(SimuPo simu, double x, double y, Long timestamp) { |
| | | String filePath = config.getOutPath() + File.separator + simu.getServiceName() + File.separator + "waters" |
| | | + File.separator + timestamp + File.separator + "water.geojson"; |
| | | if (!FileUtil.exist(filePath)) return null; |
| | | |
| | | Driver driver = null; |
| | | DataSource dataSource = null; |
| | | org.gdal.ogr.Layer layer = null; |
| | | try { |
| | | driver = ogr.GetDriverByName("GeoJSON"); |
| | | if (null == driver) return null; |
| | | |
| | | DataSource ds = driver.Open(filePath); |
| | | if (null == ds) return null; |
| | | |
| | | layer = ds.GetLayer(0); |
| | | double[] xy = GdalHelper.fromWgs84(layer.GetSpatialRef(), x, y); |
| | | |
| | | Geometry p = new Geometry(ogr.wkbPoint); |
| | | p.AddPoint_2D(xy[0], xy[1]); |
| | | p.AssignSpatialReference(layer.GetSpatialRef()); |
| | | |
| | | for (long i = 0, d = layer.GetFeatureCount(); i < d; i++) { |
| | | Feature f = layer.GetFeature(i); |
| | | if (f.GetGeometryRef().Intersects(p)) { |
| | | /*f.GetFieldAsDouble("val"); |
| | | Geometry g = f.GetGeometryRef(); |
| | | GdalHelper.fromWgs84(layer.GetSpatialRef(), g); |
| | | Double area= g.GetArea();*/ |
| | | |
| | | return f.GetGeometryRef().Area(); |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } finally { |
| | | GdalHelper.delete(layer, dataSource, driver); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据seid查询建筑物涉水深度 |
| | | */ |
| | | public List<BuildingDepthVo> getBuildingDepthBySeid(String serviceName, String seid) { |
| | | List<BuildingDepthVo> list = readBuildingJson(serviceName); |
| | | if (CollectionUtils.isEmpty(list)) return null; |