Эх сурвалжийг харах

添加接口:根据街镇名称和村居名称返回符合条件的geojson集合文件

DESKTOP-6LTVLN7\Liumouren 1 сар өмнө
parent
commit
9853b22852

+ 11 - 5
src/main/java/com/skyversation/poiaddr/controller/PoiAddressController.java

@@ -1,9 +1,6 @@
 package com.skyversation.poiaddr.controller;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.skyversation.poiaddr.addquery.AddressQueryEngine;
-import com.skyversation.poiaddr.addquery.Constant;
 import com.skyversation.poiaddr.bean.AddressResult;
 import com.skyversation.poiaddr.entity.FileDataDto;
 import com.skyversation.poiaddr.entity.PoiAddress;
@@ -13,7 +10,7 @@ import com.skyversation.poiaddr.util.ExcelReaderUtils;
 import com.skyversation.poiaddr.util.RequestUtils;
 import com.skyversation.poiaddr.util.SerializationUtils;
 import com.skyversation.poiaddr.util.fileTools.ReadFileData;
-import com.skyversation.poiaddr.util.net.AddressNetTools;
+import com.skyversation.poiaddr.util.geotools.GeoJsonIntersector;
 import com.skyversation.poiaddr.util.status.AddressLevel;
 import lombok.extern.slf4j.Slf4j;
 import org.locationtech.jts.geom.Coordinate;
@@ -21,7 +18,6 @@ import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.Point;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -77,6 +73,16 @@ public class PoiAddressController {
         return RequestUtils.request(address);
     }
 
+
+    //  根据街镇名称和村居名称返回符合条件的geojson集合文件
+    @PostMapping(value = "/selectGeojsonByNames", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
+    public Object selectGeojsonByNames(HttpServletResponse response, @RequestParam("jdNameStr") String jdNameStr, @RequestParam(name = "czNameStr", required = false) String czNameStr) throws Exception {
+        String fileName = UUID.randomUUID().toString();
+        GeoJsonIntersector.run(jdNameStr, czNameStr, fileName);
+        ReadFileData.outputFile("output/result_" + fileName + ".geojson", response);
+        return "成功";
+    }
+
     /**
      * 地名查询任务接口
      * * 参数:

+ 0 - 4
src/main/java/com/skyversation/poiaddr/util/geojsonWriter.java

@@ -1,4 +0,0 @@
-package com.skyversation.poiaddr.util;
-
-public class geojsonWriter {
-}

+ 4 - 4
src/main/java/com/skyversation/poiaddr/util/geotools/GeoJsonIntersector.java

@@ -19,19 +19,19 @@ public class GeoJsonIntersector {
 //        run("香花桥街道","香花桥居委会,朝阳村,金星村,都汇华庭居委会,盈中村,石西村,杨元村,七汇村,袁家村,郏一村,青山居委会,金巷居委会","香花桥小学");
 //        run("夏阳街道", "南门塔湾,大生桥,李腰泾,王仙村,城南村,塘郁村,枫泾村,太来村,新阳村,金家村,夏阳村,丝绸新村,志诚上和里", "豫才中学");
 //        run("盈浦街道", "南横村", "思源中学");
-        run("香花桥街道",null,"香花桥街道");
+        run("香花桥街道","","香花桥街道");
 
     }
 
     public static void run(String jdNameStr, String czNameStr, String fileName) throws Exception {
         List<String> jdNameList = new ArrayList<>(Arrays.asList(jdNameStr.split(",")));
         List<String> nameList = new ArrayList<>();
-        if(czNameStr != null){
+        if(czNameStr != null && !czNameStr.isEmpty()){
             nameList = new ArrayList<>(Arrays.asList(czNameStr.split(",")));
             System.out.println("******需要匹配的村名个数:" + nameList.size());
         }
 
-        JSONObject processingGeoJson = readGeoJson("src/main/resources/geojson/qp_cunju_2024.geojson");
+        JSONObject processingGeoJson = readGeoJson("src/main/resources/geojson/qp_cunju.geojson");
         JSONArray features = (JSONArray) processingGeoJson.get("features");
         JSONArray newFeatures = new JSONArray();
         for (Object feature : features) {
@@ -39,7 +39,7 @@ public class GeoJsonIntersector {
             String jiezhen = item.getJSONObject("properties").getString("jz");
             String cunName = item.getJSONObject("properties").getString("cjname");
             if (jdNameList.contains(jiezhen)) {
-                if(czNameStr == null){
+                if(czNameStr == null || czNameStr.isEmpty()){
                     newFeatures.add(feature);
                 }else if(nameList.contains(cunName)){
                     newFeatures.add(feature);