| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.helper.StringHelper; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.gdal.gdal.Dataset; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconst; |
| | | import org.gdal.ogr.Geometry; |
| | | import org.gdal.ogr.ogr; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | |
| | | */ |
| | | @Service |
| | | public class RasterService { |
| | | private SpatialReference sr4326; |
| | | |
| | | private SpatialReference sr4490; |
| | | |
| | | private final static Log log = LogFactory.getLog(RasterService.class); |
| | | |
| | | /** |
| | | * 初始化空间参考 |
| | | */ |
| | | public void initSr() { |
| | | if (null == sr4326) { |
| | | sr4326 = new SpatialReference(); |
| | | sr4326.ImportFromEPSG(StaticData.I4326); |
| | | } |
| | | if (null == sr4490) { |
| | | sr4490 = new SpatialReference(); |
| | | sr4490.ImportFromEPSG(StaticData.I4490); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取栅格数据的EPSG编码 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询坐标转换 |
| | | */ |
| | | public Object csTransform(double x, double y, int epsg) { |
| | | this.initSr(); |
| | | |
| | | SpatialReference srs = new SpatialReference(); |
| | | srs.ImportFromEPSG(epsg); |
| | | |
| | | Geometry point = new Geometry(ogr.wkbPoint); |
| | | point.AddPoint(x, y, 0); |
| | | point.AssignSpatialReference(srs); |
| | | |
| | | if (srs.GetName().contains(StaticData.CGCS2000)) { |
| | | point.TransformTo(sr4490); |
| | | } else { |
| | | point.TransformTo(sr4326); |
| | | } |
| | | point.SwapXY(); |
| | | |
| | | return new double[]{point.GetX(), point.GetY()}; |
| | | } |
| | | } |