| | |
| | | <artifactId>caffeine</artifactId> |
| | | <version>2.9.3</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.jetbrains</groupId> |
| | | <artifactId>annotations</artifactId> |
| | | <version>1.0.0</version> |
| | | <scope>compile</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | |
| | | return g.TransformTo(sr); |
| | | } |
| | | |
| | | public static Geometry createPolygon(SpatialReference sr, Double minx, Double miny, Double maxx, Double maxy) { |
| | | Geometry ring = new Geometry(ogr.wkbLinearRing); |
| | | ring.AddPoint_2D(minx, maxy); |
| | | ring.AddPoint_2D(maxx, maxy); |
| | | ring.AddPoint_2D(maxx, miny); |
| | | ring.AddPoint_2D(minx, miny); |
| | | ring.AddPoint_2D(minx, maxy); |
| | | |
| | | Geometry poly = new Geometry(ogr.wkbPolygon); |
| | | poly.AddGeometry(ring); |
| | | if (null != sr) { |
| | | poly.AssignSpatialReference(sr); |
| | | } |
| | | |
| | | return poly; |
| | | } |
| | | } |
| | |
| | | import com.se.simu.domain.dto.GeField; |
| | | import com.se.simu.domain.dto.GeLayer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.gdal.Band; |
| | | import org.gdal.gdal.Dataset; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconst; |
| | |
| | | } |
| | | } |
| | | |
| | | private static Geometry createPolygon(SpatialReference sr, Double minx, Double miny, Double maxx, Double maxy) { |
| | | public static Geometry createPolygon(SpatialReference sr, Double minx, Double miny, Double maxx, Double maxy) { |
| | | String epsg = sr.GetAuthorityCode(null); |
| | | if (!("4326".equals(epsg) || "4490".equals(epsg))) { |
| | | double[] dmin = GdalHelper.fromWgs84(sr, minx, miny); |
| | |
| | | |
| | | Geometry poly = new Geometry(ogr.wkbPolygon); |
| | | poly.AddGeometry(ring); |
| | | poly.AssignSpatialReference(sr); |
| | | |
| | | return poly; |
| | | } |
| | |
| | | /** |
| | | * 创建Geometry对象 |
| | | */ |
| | | private static Geometry createGeometry(GeLayer geLayer, JSONObject geom) { |
| | | public static Geometry createGeometry(GeLayer geLayer, JSONObject geom) { |
| | | String type = geom.getStr("type"); |
| | | JSONArray cs = geom.getJSONArray("coordinates"); |
| | | |
| | |
| | | import org.gdal.gdal.WarpOptions; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconst; |
| | | import org.gdal.ogr.Geometry; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | |
| | | List<GeLayer> layers = getLayers(token, db); |
| | | queryData(token, db, layers); |
| | | checkData(layers); |
| | | checkData(data, db, layers); |
| | | createShps(basePath, layers); |
| | | createZoneShp(basePath, data, db.getSpatialReference()); |
| | | if (data.getPid() > 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | private void checkData(List<GeLayer> layers) { |
| | | private void checkData(DataPo data, GeDb db, List<GeLayer> layers) { |
| | | GeLayer point = getLayerByName(layers, config.getLayerNames().get(0)); |
| | | GeLayer line = getLayerByName(layers, config.getLayerNames().get(1)); |
| | | GeLayer build = getLayerByName(layers, config.getLayerNames().get(2)); |
| | | |
| | | Geometry extent = ShpHelper.createPolygon(db.getSpatialReference(), data.getMinx(), data.getMiny(), data.getMaxx(), data.getMaxy()); |
| | | checkSpatialRange(extent, point); |
| | | checkSpatialRange(extent, build); |
| | | |
| | | List<String> bsm = getValues(point, "bsm"); |
| | | List<String> bsm2 = new ArrayList<>(bsm); |
| | |
| | | layers.add(juncLayer); |
| | | } |
| | | |
| | | private void checkSpatialRange(Geometry extent, GeLayer geLayer) { |
| | | int i = 0; |
| | | while (i < geLayer.getData().size()) { |
| | | JSONObject geom = geLayer.getData().getJSONObject(i).getJSONObject("geometry"); |
| | | Geometry g = ShpHelper.createGeometry(geLayer, geom); |
| | | g.AssignSpatialReference(extent.GetSpatialReference()); |
| | | |
| | | if (!extent.Intersects(g)) { |
| | | geLayer.getData().remove(i); |
| | | continue; |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | private GeLayer getLayerByName(List<GeLayer> layers, String name) { |
| | | return layers.stream().filter(a -> a.getName().equals(name)).findFirst().orElse(null); |
| | | } |