| | |
| | | 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; |
| | | |
| | |
| | | |
| | | 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}; |
| | | } |
| | | } |