| | |
| | | import com.se.simu.domain.po.DataPo; |
| | | import com.se.simu.domain.po.SimuPo; |
| | | import com.se.simu.domain.vo.*; |
| | | import com.se.simu.domain.vo.Layer; |
| | | import com.se.simu.helper.GdalHelper; |
| | | import com.se.simu.helper.StringHelper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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 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 { |
| | |
| | | } |
| | | |
| | | public Double getWaterArea(SimuPo simu, double x, double y, Long timestamp) { |
| | | return null; |
| | | 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; |