Explorar el Código

新增 坐标系获取列表、坐标系获取信息接口

欧阳劲驰 hace 3 semanas
padre
commit
11a15843b7

+ 136 - 0
src/main/java/com/shkpr/service/alambizplugin/bizservice/GisSurveyCRSBizService.java

@@ -0,0 +1,136 @@
+package com.shkpr.service.alambizplugin.bizservice;
+
+import com.global.base.log.LogLevelFlag;
+import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.commtools.BeanUtil;
+import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
+import com.shkpr.service.alambizplugin.dto.CommCRSBoundingBox;
+import com.shkpr.service.alambizplugin.dto.CommCRSInfo;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.geotools.metadata.iso.extent.GeographicBoundingBoxImpl;
+import org.geotools.referencing.CRS;
+import org.geotools.referencing.ReferencingFactoryFinder;
+import org.geotools.referencing.crs.DefaultGeographicCRS;
+import org.geotools.referencing.factory.epsg.DirectEpsgFactory;
+import org.opengis.metadata.Identifier;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.util.GenericName;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * 坐标系管理service
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Component
+public class GisSurveyCRSBizService {
+    /**
+     * log
+     */
+    private final static String mStrClassName = "GisSurveyCRSBizService";
+    private final static String mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
+
+    /**
+     * 坐标系所属系统
+     */
+    private final static String AUTHORITY = "EPSG";
+    /**
+     * 坐标系工厂
+     */
+    private final static CRSAuthorityFactory crsFactory = ReferencingFactoryFinder.getCRSAuthorityFactory(AUTHORITY, null);
+
+    /**
+     * 获取坐标系列表
+     * <p>此处从 {@code HSQL} 数据库读取crs信息</br>
+     * {@link DirectEpsgFactory} 会在首次查询后缓存,所以每次从{@link CRSAuthorityFactory}获取即可</p>
+     *
+     * @return 坐标系列表
+     * @see DirectEpsgFactory#getAuthorityCodes
+     * @see org.geotools.referencing.factory.epsg.AuthorityCodes
+     */
+    public List<Item> getCRSList() {
+        try {
+            List<Item> results = new ArrayList<>();
+
+            //获取code集合,遍历获取描述信息
+            Set<String> codes = crsFactory.getAuthorityCodes(CoordinateReferenceSystem.class);
+            for (String code : codes) {
+                code = code.trim();
+                String desc = crsFactory.getDescriptionText(AUTHORITY + ":" + code).toString();
+
+                results.add(new Item(code, desc));
+            }
+
+            return results;
+        } catch (FactoryException e) {
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format("CRS解析异常: error:%s", e));
+            return Collections.emptyList();
+        }
+    }
+
+
+    /**
+     * 获取坐标系信息
+     *
+     * @param code 坐标系code
+     * @return 坐标系信息
+     */
+    public CommCRSInfo getCRSInfo(String code) {
+        try {
+            //获取code集合
+            Set<String> codes = crsFactory.getAuthorityCodes(CoordinateReferenceSystem.class);
+            if (!codes.contains(code)) return null;
+            //获取crs
+            CoordinateReferenceSystem crs = CRS.decode(AUTHORITY + ":" + code, true);
+            if (crs == null) return null;
+            //构建结果
+            CommCRSInfo result = new CommCRSInfo();
+            //基本信息
+            result.setName(crs.getName().getCode());
+            result.setCode(crs.getIdentifiers().stream().map(Identifier::getCode).collect(Collectors.joining(",")));
+            result.setDimension(crs.getCoordinateSystem().getDimension());
+            result.setRemarks(crs.getRemarks().toString());
+            result.setAlias(crs.getAlias().stream().map(GenericName::toString).collect(Collectors.toList()));
+            result.setWkt(crs.toWKT());
+            //范围
+            result.setBoundingBoxes(crs.getDomainOfValidity().getGeographicElements().stream()
+                    .filter(it -> it instanceof GeographicBoundingBoxImpl)
+                    .map(it -> {
+                        GeographicBoundingBoxImpl boundingBox = (GeographicBoundingBoxImpl) it;
+                        return BeanUtil.copy(boundingBox, CommCRSBoundingBox.class);
+                    }).collect(Collectors.toList()));
+            result.setBoundingBoxDescription(crs.getDomainOfValidity().getDescription().toString());
+            //基准
+            if (crs instanceof DefaultGeographicCRS) {
+                GeodeticDatum datum = ((DefaultGeographicCRS) crs).getDatum();
+                result.setDatumName(datum.getName().getCode());
+                result.setDatumCode(datum.getIdentifiers().stream().map(Identifier::getCode).collect(Collectors.joining(",")));
+            }
+
+            return result;
+        } catch (FactoryException e) {
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format("CRS解析异常: error:%s", e));
+            return null;
+        }
+    }
+
+    @Data
+    @AllArgsConstructor
+    public static class Item {
+        String code;
+        String desc;
+    }
+}

+ 1 - 1
src/main/java/com/shkpr/service/alambizplugin/components/checker/DuplicatePointsFinder.java

@@ -271,7 +271,7 @@ public class DuplicatePointsFinder {
      *
      * @param coordinate   坐标
      * @param lngScale     经度精度
-     * @param latScale     度精度
+     * @param latScale     度精度
      * @param lngTolerance 经度公差
      * @param latTolerance 纬度公差
      * @return 边界

+ 2 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/ApiURI.java

@@ -37,6 +37,8 @@ public class ApiURI {
     public static final String URI_XXX_THIRD_EXPORT_GET = "third-export-get";
     public static final String URI_XXX_CAD_CONVERT = "cad-convert";
     public static final String URI_XXX_CAD_CONVERT_GET = "cad-convert-get";
+    public static final String URI_XXX_CRS_GET_LIST = "crs-get-list";
+    public static final String URI_XXX_CRS_GET_INFO = "crs-get-info";
     public static final String URI_XXX_TEMP_FILES = "temp-files";
     public static final String URI_XXX_ASYNC_RESULTS = "async-results";
 

+ 141 - 0
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -7,6 +7,7 @@ import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyCheckParams;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdExportParams;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdImportParams;
+import com.shkpr.service.alambizplugin.bizservice.GisSurveyCRSBizService;
 import com.shkpr.service.alambizplugin.bizservice.GisSurveyCadConvertBizService;
 import com.shkpr.service.alambizplugin.bizservice.GisSurveySystemCheckBizService;
 import com.shkpr.service.alambizplugin.bizservice.GisSurveyThirdExportBizService;
@@ -24,6 +25,7 @@ import com.shkpr.service.alambizplugin.controllervalid.CommonParamValidSK;
 import com.shkpr.service.alambizplugin.dbdao.services.GisSurveyLayerApplyThirdCopyServiceImpl;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyService;
 import com.shkpr.service.alambizplugin.dto.CommAsyncResult;
+import com.shkpr.service.alambizplugin.dto.CommCRSInfo;
 import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyThirdCopy;
 import com.shkpr.service.alambizplugin.dto.GisSurveySystemCheckResultDetail;
 import com.shkpr.service.alambizplugin.dto.GisSurveyThirdImportResult;
@@ -69,9 +71,12 @@ public class ApiGisSurveyController {
     private final AtomicInteger mSeqThirdExportReq;
     private final AtomicInteger mSeqThirdExportGetReq;
     private final AtomicInteger mSeqCadConvertGetReq;
+    private final AtomicInteger mSeqCrsGetListReq;
+    private final AtomicInteger mSeqCrsGetInfoReq;
 
     private final ObjectMapper objectMapper;
 
+    private final GisSurveyCRSBizService crsBizService;
     private final GisSurveySystemCheckBizService systemCheckBizService;
     private final GisSurveyThirdImportBizService thirdImportBizService;
     private final GisSurveyThirdExportBizService thirdExportBizService;
@@ -80,6 +85,7 @@ public class ApiGisSurveyController {
     private final GisSurveyLayerApplyThirdCopyServiceImpl layerApplyThirdCopyService;
 
     public ApiGisSurveyController(ObjectMapper objectMapper
+            , GisSurveyCRSBizService crsBizService
             , GisSurveySystemCheckBizService systemCheckBizService
             , GisSurveyThirdImportBizService thirdImportBizService
             , GisSurveyThirdExportBizService thirdExportBizService
@@ -99,7 +105,10 @@ public class ApiGisSurveyController {
         mSeqThirdExportGetReq = new AtomicInteger(0);
         mSeqCadConvertReq = new AtomicInteger(0);
         mSeqCadConvertGetReq = new AtomicInteger(0);
+        mSeqCrsGetListReq = new AtomicInteger(0);
+        mSeqCrsGetInfoReq = new AtomicInteger(0);
         this.objectMapper = objectMapper;
+        this.crsBizService = crsBizService;
         this.systemCheckBizService = systemCheckBizService;
         this.thirdImportBizService = thirdImportBizService;
         this.thirdExportBizService = thirdExportBizService;
@@ -980,4 +989,136 @@ public class ApiGisSurveyController {
                         , resResult.getTimestamp() - llReqBefore));
         return resResult;
     }
+
+    /**
+     * 获取crs列表
+     *
+     * @param request       request
+     * @param strClientType 客户端类型
+     * @param strUserAgent  用户信息
+     * @return crs列表
+     */
+    @GetMapping(value = ApiURI.URI_XXX_CRS_GET_LIST)
+    public ResponseRes<String> crsGetList(HttpServletRequest request
+            , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
+            , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent) {
+        //入参校验
+        final String URI_PATH = request.getRequestURI();
+        final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
+        final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
+
+
+        //begin
+        long llReqBefore = System.currentTimeMillis();
+        String strRunSeq = String.format("%d-%d", llReqBefore, mSeqCrsGetListReq.incrementAndGet());
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
+                , String.format("%s:%s seq:{%s} begin====>"
+                        , strPlatform
+                        , URI_PATH
+                        , strRunSeq));
+
+        //构建result
+        ResponseRes<String> resResult = new ResponseRes<>();
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
+
+        //获取crs列表
+        List<GisSurveyCRSBizService.Item> result = crsBizService.getCRSList();
+        String resultStr = null;
+        try {
+            if (result != null) resultStr = objectMapper.writeValueAsString(result);
+        } catch (JsonProcessingException e) {
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format("Json序列化异常: error:%s", e));
+        }
+
+        //执行成功
+        if (resultStr != null) {
+            resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+            resResult.setResdata(resultStr);
+        }
+
+        //end
+        resResult.setTimestamp(System.currentTimeMillis());
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
+                , String.format("%s:%s seq:{%s} rescode:{%s} resmsg:{%s} time:{%d ms} end<===="
+                        , strPlatform
+                        , URI_PATH
+                        , strRunSeq
+                        , resResult.getRescode()
+                        , resResult.getResmsg()
+                        , resResult.getTimestamp() - llReqBefore));
+        return resResult;
+    }
+
+    /**
+     * 获取crs信息
+     *
+     * @param request       request
+     * @param strClientType 客户端类型
+     * @param strUserAgent  用户信息
+     * @return crs信息
+     */
+    @GetMapping(value = ApiURI.URI_XXX_CRS_GET_INFO)
+    public ResponseRes<String> crsGetInfo(HttpServletRequest request
+            , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
+            , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
+            , @RequestParam(value = "code", required = false) String code) throws SelfException {
+        //入参校验
+        final String URI_PATH = request.getRequestURI();
+        final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
+        final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
+        if (StringUtils.isAnyBlank(code) || StringUtils.length(code) > 64) {
+            throw new SelfException(ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrCode()
+                    , String.format(ApiURI.EXCEPTION_FORMAT
+                    , strPlatform
+                    , URI_PATH
+                    , ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrMsg()));
+        }
+
+
+        //begin
+        long llReqBefore = System.currentTimeMillis();
+        String strRunSeq = String.format("%d-%d", llReqBefore, mSeqCrsGetInfoReq.incrementAndGet());
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
+                , String.format("%s:%s seq:{%s} begin====>"
+                        , strPlatform
+                        , URI_PATH
+                        , strRunSeq));
+
+        //构建result
+        ResponseRes<String> resResult = new ResponseRes<>();
+        resResult.setRescode(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrCode());
+        resResult.setResmsg(ResponseCode.RESULT_ASYNC_TASK_FAILED.toStrMsg());
+
+        //获取crs列表
+        CommCRSInfo result = crsBizService.getCRSInfo(code);
+        String resultStr = null;
+        try {
+            if (result != null) resultStr = objectMapper.writeValueAsString(result);
+        } catch (JsonProcessingException e) {
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                    , String.format("Json序列化异常: error:%s", e));
+        }
+
+        //执行成功
+        if (resultStr != null) {
+            resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+            resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+            resResult.setResdata(resultStr);
+        }
+
+        //end
+        resResult.setTimestamp(System.currentTimeMillis());
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
+                , String.format("%s:%s seq:{%s} rescode:{%s} resmsg:{%s} time:{%d ms} end<===="
+                        , strPlatform
+                        , URI_PATH
+                        , strRunSeq
+                        , resResult.getRescode()
+                        , resResult.getResmsg()
+                        , resResult.getTimestamp() - llReqBefore));
+        return resResult;
+    }
 }

+ 2 - 0
src/main/java/com/shkpr/service/alambizplugin/controllerfilter/third/ApiJWTGisSurveyBizFilter.java

@@ -31,6 +31,8 @@ public class ApiJWTGisSurveyBizFilter extends JWTAuthenticationFilter {
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_THIRD_EXPORT_GET), "GET");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_CAD_CONVERT), "POST");
         msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_CAD_CONVERT_GET), "GET");
+        msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_CRS_GET_LIST), "GET");
+        msMapURI2Method.put(String.format("%s/%s", ApiURI.URI_GIS_SURVEY_H, ApiURI.URI_XXX_CRS_GET_INFO), "GET");
     }
 
     public ApiJWTGisSurveyBizFilter(String url, AuthenticationManager authenticationManager){

+ 36 - 0
src/main/java/com/shkpr/service/alambizplugin/dto/CommCRSBoundingBox.java

@@ -0,0 +1,36 @@
+package com.shkpr.service.alambizplugin.dto;
+
+import lombok.Data;
+
+/**
+ * 通用crs边界框
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+public class CommCRSBoundingBox {
+    /**
+     * The western-most coordinate of the limit of the dataset extent. The value is expressed in longitude in decimal
+     * degrees (positive east).
+     */
+    private double westBoundLongitude;
+
+    /**
+     * The eastern-most coordinate of the limit of the dataset extent. The value is expressed in longitude in decimal
+     * degrees (positive east).
+     */
+    private double eastBoundLongitude;
+
+    /**
+     * The southern-most coordinate of the limit of the dataset extent. The value is expressed in latitude in decimal
+     * degrees (positive north).
+     */
+    private double southBoundLatitude;
+
+    /**
+     * The northern-most, coordinate of the limit of the dataset extent. The value is expressed in latitude in decimal
+     * degrees (positive north).
+     */
+    private double northBoundLatitude;
+}

+ 55 - 0
src/main/java/com/shkpr/service/alambizplugin/dto/CommCRSInfo.java

@@ -0,0 +1,55 @@
+package com.shkpr.service.alambizplugin.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 通用坐标系信息
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+public class CommCRSInfo {
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 编码
+     */
+    private String code;
+    /**
+     * crs纬度
+     */
+    private Integer dimension;
+    /**
+     * 备注
+     */
+    private String remarks;
+    /**
+     * 别名
+     */
+    private List<String> alias;
+    /**
+     * wkt
+     */
+    private String wkt;
+    /**
+     * 范围框
+     */
+    private List<CommCRSBoundingBox> boundingBoxes;
+    /**
+     * 范围描述
+     */
+    private String boundingBoxDescription;
+    /**
+     * 基准名称
+     */
+    private String datumName;
+    /**
+     * 基准编码
+     */
+    private String datumCode;
+}