| | |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.geotools.geometry.DirectPosition2D; |
| | | import org.geotools.geometry.jts.JTS; |
| | | import org.geotools.referencing.CRS; |
| | | import org.geotools.referencing.GeodeticCalculator; |
| | | import org.locationtech.jts.geom.Geometry; |
| | | import org.locationtech.jts.io.WKTReader; |
| | | import org.opengis.referencing.crs.CRSAuthorityFactory; |
| | | import org.opengis.referencing.crs.CoordinateReferenceSystem; |
| | | import org.opengis.referencing.operation.MathTransform; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | |
| | |
| | | * @date 2023-09-14 |
| | | */ |
| | | public class GeoHelper { |
| | | public static SpatialReference sr4326; |
| | | |
| | | public static SpatialReference sr4490; |
| | | |
| | | public static SpatialReference sr104903; |
| | | |
| | | public final static double MOON_RADIUS = 1738000; |
| | |
| | | */ |
| | | public static void initSr() { |
| | | try { |
| | | sr4326 = new SpatialReference(); |
| | | sr4326.ImportFromEPSG(StaticData.I4326); |
| | | |
| | | sr4490 = new SpatialReference(); |
| | | sr4490.ImportFromEPSG(StaticData.I4490); |
| | | |
| | | sr104903 = new SpatialReference(StaticData.MOON_2000_WKT); |
| | | |
| | | crs104903 = CRS.parseWKT(StaticData.MOON_2000_WKT); |
| | |
| | | |
| | | return gc.getDestinationGeographicPoint(); |
| | | } |
| | | |
| | | /** |
| | | * 坐标转换 |
| | | */ |
| | | public static double[] csTransform(double x, double y, int epsg) throws Exception { |
| | | CRSAuthorityFactory factory = CRS.getAuthorityFactory(true); |
| | | CoordinateReferenceSystem target = factory.createCoordinateReferenceSystem("EPSG:4326"); |
| | | |
| | | CoordinateReferenceSystem sourceCrs = CRS.decode("EPSG:" + epsg); |
| | | CoordinateReferenceSystem targetCrs = CRS.decode("EPSG:4326"); |
| | | MathTransform transform = CRS.findMathTransform(sourceCrs, targetCrs, true); |
| | | |
| | | WKTReader reader = new WKTReader(); |
| | | Geometry geometry = reader.read("POINT (" + x + " " + y + ")"); |
| | | geometry.setSRID(epsg); |
| | | |
| | | Geometry geo = JTS.transform(geometry, transform); |
| | | |
| | | return new double[]{geo.getCoordinate().x, geo.getCoordinate().y}; |
| | | } |
| | | } |