| | |
| | | import com.se.simu.domain.dto.GeLayer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.ogr.*; |
| | | import org.gdal.osr.CoordinateTransformation; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.gdal.osr.osr; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | } |
| | | } |
| | | |
| | | private static void createFields(Layer layer,Map<String, Object> map) { |
| | | private static void createFields(Layer layer, Map<String, Object> map) { |
| | | for (String key : map.keySet()) { |
| | | Object val = map.get(key); |
| | | switch (val.getClass().getTypeName()) { |
| | |
| | | private static Geometry createPolygon(SpatialReference sr, Double minx, Double miny, Double maxx, Double maxy) { |
| | | String epsg = sr.GetAuthorityCode(null); |
| | | if (!("4326".equals(epsg) || "4490".equals(epsg))) { |
| | | double[] dmin = fromWgs84(sr, minx, miny); |
| | | double[] dmax = fromWgs84(sr, maxx, maxy); |
| | | double[] dmin = GdalHelper.fromWgs84(sr, minx, miny); |
| | | double[] dmax = GdalHelper.fromWgs84(sr, maxx, maxy); |
| | | minx = dmin[0]; |
| | | miny = dmin[1]; |
| | | maxx = dmax[0]; |
| | |
| | | |
| | | private String getEpsg(SpatialReference sr) { |
| | | return sr.GetAuthorityCode(null); |
| | | } |
| | | |
| | | /** |
| | | * 转换为WGS84坐标 |
| | | */ |
| | | public static Geometry toWgs84(SpatialReference sr, double x, double y) { |
| | | Geometry point = new Geometry(ogr.wkbPoint); |
| | | point.AssignSpatialReference(sr); |
| | | point.AddPoint(x, y); |
| | | |
| | | point.TransformTo(GdalHelper.SR4326); |
| | | //point.SwapXY(); |
| | | |
| | | return point; |
| | | } |
| | | |
| | | /** |
| | | * WGS84转换为目标坐标 |
| | | */ |
| | | public static double[] fromWgs84(SpatialReference sr, double x, double y) { |
| | | // https://blog.csdn.net/weixin_34910922/article/details/129208661 |
| | | CoordinateTransformation ct = new CoordinateTransformation(GdalHelper.SR4326, sr); |
| | | if (sr.IsProjected() != 1) { |
| | | sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER); |
| | | } |
| | | |
| | | return ct.TransformPoint(x, y); |
| | | } |
| | | } |