From b8f2c19b869986efa519f1846b63b11378147861 Mon Sep 17 00:00:00 2001
From: zrj <646384940@qq.com>
Date: Tue, 05 Nov 2024 22:11:27 +0800
Subject: [PATCH] 增加空间数据和基础接口及shp导入导出

---
 src/main/java/org/springblade/common/utils/ShapeFileUtil.java |   45 +++++++++++++++++++++++++++++----------------
 1 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/springblade/common/utils/ShapeFileUtil.java b/src/main/java/org/springblade/common/utils/ShapeFileUtil.java
index 77242ad..efcb2aa 100644
--- a/src/main/java/org/springblade/common/utils/ShapeFileUtil.java
+++ b/src/main/java/org/springblade/common/utils/ShapeFileUtil.java
@@ -15,6 +15,7 @@
 import org.locationtech.jts.geom.*;
 import org.locationtech.jts.io.ParseException;
 import org.locationtech.jts.io.WKTReader;
+import org.opengis.feature.GeometryAttribute;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.filter.Filter;
@@ -39,7 +40,10 @@
 	 * @param geomType           geometry类型
 	 * @param saveFolder         导出位置
 	 */
-	private static void exportShp(List<Map<String, Object>> dataPropertiesList, String fileName, String geomType,String saveFolder) {
+	public static void exportShp(List<Map<String, Object>> dataPropertiesList,
+								 String fileName,
+								 String geomType,
+								 String saveFolder) {
 		//创建保存shp文件夹
 		File dir = new File(saveFolder);
 		if (!dir.exists()) {
@@ -194,13 +198,17 @@
 				featureJSON.writeFeature(feature, writer);
 				String temp = writer.toString();
 				JSONObject json = JSONObject.parseObject(temp);
-
+				Object value = feature.getDefaultGeometryProperty().getValue();
 				try {
 					// 空间坐标
-					shpDTO.put("geometry",json.getJSONObject("geometry").getString("coordinates"));
+					shpDTO.put("geometry",value);
 					// 空间类型
 					if (json.getJSONObject("geometry").get("type") != null) {
-						shpDTO.put("geoType",json.getJSONObject("geometry").getString("type"));
+						shpDTO.put("type",json.getJSONObject("geometry").getString("type"));
+					}
+					// 名称
+					if (json.getJSONObject("properties").get("name")!= null) {
+						shpDTO.put("name",json.getJSONObject("properties").getString("name"));
 					}
 					dtoList.add(shpDTO);
 				} catch (NumberFormatException e) {
@@ -220,22 +228,27 @@
 
 	public static void main(String[] args) throws IOException, ParseException {
 //		File file = new File("F:\\test4jdata\\shp\\import\\zrq.zip");
-		File file = new File("F:\\test4jdata\\shp\\export\\test.zip");
+		File file = new File("F:\\test4jdata\\shp\\zip\\test.zip");
 		List<Map<String, Object>> list = shpToGeoJson(file);
 		System.out.println("list = " + list);
 
 		// 导出shp 文件
-		List<Map<String,Object>> propertyList = new ArrayList<>();
-		for (int i = 0; i < 3; i++) {
-			Map<String,Object> map = new HashMap<>();
-			map.put("ID", i);
-			map.put("名称", "test" + i);
-			map.put("描述", "测试shp导出" + i);
-			map.put("geometry", "MULTILINESTRING ((114.0888763800001 22.549298400000055, 114.0897166200001 22.54931240800005, 114.09006708000004 22.549318250000056, 114.09104754000009 22.549328150000065))");
-			propertyList.add(map);
-		}
-		String exportPath = "F:\\test4jdata\\shp\\export\\";
-		exportShp(propertyList, "test", "MultiLineString",exportPath);
+//		List<Map<String,Object>> propertyList = new ArrayList<>();
+//		for (int i = 0; i < 3; i++) {
+//			Map<String,Object> map = new HashMap<>();
+//			map.put("ID", i);
+//			map.put("名称", "test" + i);
+//			map.put("描述", "测试shp导出" + i);
+//			map.put("geometry", "MULTILINESTRING ((114.0888763800001 22.549298400000055, 114.0897166200001 22.54931240800005, 114.09006708000004 22.549318250000056, 114.09104754000009 22.549328150000065))");
+//			propertyList.add(map);
+//		}
+//		String exportPath = "F:\\test4jdata\\shp\\export\\";
+//		exportShp(propertyList, "test", "MultiLineString",exportPath);
+//		// 打包成 zip 包,然后导出
+//		String zipPath = "F:\\test4jdata\\shp\\zip\\test.zip";
+//		boolean folder = ZipUtil.zipFolder(exportPath, zipPath);
+		// 打包成功后导出
+
 	}
 
 	public static double[] getLongitudeLatitude(Geometry wktPoint) throws ParseException {

--
Gitblit v1.9.3