• 坐标系之前的数据转换(比如3857转4326)


    implementation("org.osgeo:proj4j:0.1.0")
    
    import org.osgeo.proj4j.*;
    
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.List;
    
    
    public class CoordinateSystemUtils {
    
        public static double[] translateExtent(Integer sourceEPSG, Integer targetEPSG, double xmin, double ymin) {
            CoordinateTransformFactory transformFactory = new CoordinateTransformFactory();
            CRSFactory crsFactory = new CRSFactory();
            CoordinateReferenceSystem source = crsFactory.createFromName("EPSG:" + sourceEPSG);
            CoordinateReferenceSystem target = crsFactory.createFromName("EPSG:" + targetEPSG);
    
            CoordinateTransform transform = transformFactory.createTransform(source, target);
            ProjCoordinate minCoordinate = new ProjCoordinate(xmin, ymin);
            transform.transform(minCoordinate, minCoordinate);
            double[] box = new double[]{minCoordinate.x, minCoordinate.y};
            return box;
        }
    
        public static void main(String[] args) {
    //        List<Double> list = new ArrayList<>();
    //        list.add(13369378.41490000D);
    //        list.add(4072485.38040000D);
    //        System.out.println(JSON.toJSONString(translateExtent(4490, 3857, list)));
            double[] a = translateExtent(3857, 4490, 13369378.41490000D, 4072485.38040000D);
            System.out.println(a);
        }
    
        public static List<Double> translateExtent(Integer sourceEPSG, Integer targetEPSG, List<BigDecimal> data){
            if(data == null || data.size() < 2){
                return null;
            }
            List<Double> list = new ArrayList<>();
            CoordinateTransformFactory transformFactory = new CoordinateTransformFactory();
            CRSFactory crsFactory = new CRSFactory();
            CoordinateReferenceSystem source = crsFactory.createFromName("EPSG:" + sourceEPSG);
            CoordinateReferenceSystem target = crsFactory.createFromName("EPSG:" + targetEPSG);
    
            CoordinateTransform transform = transformFactory.createTransform(source, target);
            if(data.size() == 2){
                ProjCoordinate minCoordinate = new ProjCoordinate(data.get(0).doubleValue(), data.get(1).doubleValue());
                transform.transform(minCoordinate, minCoordinate);
                list.add(minCoordinate.x);
                list.add(minCoordinate.y);
                return list;
            }else if(data.size() == 3){
                ProjCoordinate minCoordinate = new ProjCoordinate(data.get(0).doubleValue(), data.get(1).doubleValue(), data.get(2).doubleValue());
                transform.transform(minCoordinate, minCoordinate);
                list.add(minCoordinate.x);
                list.add(minCoordinate.y);
                list.add(minCoordinate.z);
                return list;
            }
            return list;
        }
    
        public static List<Double> translateExtentByDouble(Integer sourceEPSG, Integer targetEPSG, List<Double> data){
            if(data == null || data.size() < 2){
                return null;
            }
            List<Double> list = new ArrayList<>();
            CoordinateTransformFactory transformFactory = new CoordinateTransformFactory();
            CRSFactory crsFactory = new CRSFactory();
            CoordinateReferenceSystem source = crsFactory.createFromName("EPSG:" + sourceEPSG);
            CoordinateReferenceSystem target = crsFactory.createFromName("EPSG:" + targetEPSG);
    
            CoordinateTransform transform = transformFactory.createTransform(source, target);
            if(data.size() == 2){
                ProjCoordinate minCoordinate = new ProjCoordinate(data.get(0), data.get(1));
                transform.transform(minCoordinate, minCoordinate);
                list.add(minCoordinate.x);
                list.add(minCoordinate.y);
                return list;
            }else if(data.size() == 3){
                ProjCoordinate minCoordinate = new ProjCoordinate(data.get(0), data.get(1), data.get(2));
                transform.transform(minCoordinate, minCoordinate);
                list.add(minCoordinate.x);
                list.add(minCoordinate.y);
                list.add(minCoordinate.z);
                return list;
            }
            return list;
        }
    
    
    }
    

      

  • 相关阅读:
    (七)执行上下文和词法作用域&动态作用域案例分析
    (六)js的arguments
    (五)关于解构赋值
    (四)JavaScript深入之词法作用域和动态作用域
    jmeter获取token并请求失败Internal authentication failed 400
    jmeter造当前时间,未来时间,历史时间
    jmater分布式压力测试总结
    敏捷测试-基本流程
    致我测试之路的“七年之痒”
    jmeter解决登录token获取
  • 原文地址:https://www.cnblogs.com/james-roger/p/14962462.html
Copyright © 2020-2023  润新知