Explorar o código

增加创建圆方法(备用)

欧阳劲驰 hai 2 semanas
pai
achega
810188b923

+ 7 - 4
src/main/java/com/shkpr/service/alambizplugin/commtools/GeomUtil.java

@@ -9,9 +9,9 @@ import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Envelope;
 import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.Polygon;
-import org.locationtech.jts.geom.PrecisionModel;
 import org.locationtech.jts.util.GeometricShapeFactory;
 import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
 
 /**
@@ -29,7 +29,7 @@ public class GeomUtil {
     /**
      * geom工厂
      */
-    private static final GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4490);
+    private static final GeometryFactory geometryFactory = new GeometryFactory();
     /**
      * 形状工厂
      */
@@ -51,9 +51,12 @@ public class GeomUtil {
             double lng = centre.getX();
             //纬度
             double lat = centre.getY();
+            //坐标系
+            CoordinateReferenceSystem crs = CRS.decode("EPSG:" + crsCode);
+            if (crs == null) return null;
 
             //创建大地计算器,并设置坐标系
-            GeodeticCalculator gc = new GeodeticCalculator(CRS.decode("EPSG:4490"));
+            GeodeticCalculator gc = new GeodeticCalculator(crs);
 
             //计算东点(90度),正东移动
             gc.setStartingGeographicPoint(lng, lat);
@@ -101,7 +104,7 @@ public class GeomUtil {
             //创建圆
             Polygon circle = shapeFactory.createCircle();
             //设置坐标系
-            circle.setSRID(4490);
+            circle.setSRID(Integer.parseInt(crsCode));
 
             return circle;
         } catch (TransformException | FactoryException e) {