Java实现用geotools库将WGS84坐标经纬度反转为utm+51坐标经纬度,坐标反转方法
时间: 2024-06-12 16:06:34 浏览: 344
1. 引入geotools库
在Java项目中,需要引入geotools库的依赖,可以使用Maven或者手动导入jar包的方式。具体可以参考官方文档:https://docs.geotools.org/latest/userguide/library/referencing/install.html
2. 创建WGS84和UTM 51坐标系对象
使用geotools库,可以通过以下方式创建WGS84和UTM 51坐标系对象:
```java
// 创建WGS84坐标系对象
CoordinateReferenceSystem crsWGS84 = CRS.decode("EPSG:4326");
// 创建UTM 51坐标系对象
CoordinateReferenceSystem crsUTM51 = CRS.decode("EPSG:32651");
```
其中,EPSG:4326代表WGS84坐标系,EPSG:32651代表UTM 51坐标系。
3. 创建坐标转换对象
使用geotools库,可以通过以下方式创建坐标转换对象:
```java
// 创建从WGS84坐标系到UTM 51坐标系的转换对象
MathTransform transform = CRS.findMathTransform(crsWGS84, crsUTM51);
```
4. 进行坐标转换
使用坐标转换对象,可以将WGS84坐标系的经纬度坐标转换为UTM 51坐标系的坐标:
```java
// 创建WGS84坐标系的经纬度坐标
double lon = 121.473704;
double lat = 31.230393;
Coordinate coordWGS84 = new Coordinate(lon, lat);
// 将WGS84坐标系的经纬度坐标转换为UTM 51坐标系的坐标
Coordinate coordUTM51 = JTS.transform(coordWGS84, null, transform);
```
其中,JTS是geotools库中用于进行空间计算的工具类,可以通过以下方式导入:
```java
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.PrecisionModel;
import org.locationtech.jts.geom.impl.CoordinateArraySequence;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;
import org.locationtech.jts.io.geojson.GeoJsonReader;
import org.locationtech.jts.io.geojson.GeoJsonWriter;
import org.locationtech.jts.operation.distance.DistanceOp;
import org.locationtech.jts.operation.distance.GeometryLocation;
import org.locationtech.jts.operation.distance.IndexedFacetDistance;
import org.locationtech.jts.operation.distance.PointPairDistance;
import org.locationtech.jts.operation.overlay.OverlayOp;
import org.locationtech.jts.operation.union.CascadedPolygonUnion;
import org.locationtech.jts.operation.union.UnaryUnionOp;
import org.locationtech.jts.precision.GeometryPrecisionReducer;
import org.locationtech.jts.util.GeometricShapeFactory;
import org.locationtech.jts.util.GeometricShapeFactory.EnvelopeInternal;
```
阅读全文
相关推荐















