From 8d9a2d656e4ae007590c622e5f7c228adacdca49 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 14 Jun 2024 10:11:36 +0800
Subject: [PATCH] 统一风格
---
src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java | 27 ++++++++++-----------------
1 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java b/src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java
index b1325f4..baeb13d 100644
--- a/src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java
+++ b/src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java
@@ -11,21 +11,14 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
-
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
public class ShapeFileUtil {
- /*
- * @param zipFile: 压缩包文件地址
- * @return FeatureCollection
- * @author pangshicheng
- * @description 解析shp压缩包,并返回解析出的 FeatureCollection
- * @date 2023/7/18 16:02
- */
+ //将文件解压
public static FeatureCollection getFeatureCollectionByShpFile(File zipFile) throws IOException {
try {
String tempDir = FileUtil.getTmpDirPath();
@@ -54,28 +47,28 @@
Filter filter = Filter.INCLUDE;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
return collection;
- }catch (Exception e){
+ } catch (Exception e) {
throw e;
}
}
+
/**
* @param zipFile:
* @return JSONObject
- * @author pangshicheng
* @description 通过shp压缩文件,将其转换为GeoJson格式
- * @date 2023/7/18 16:04
*/
+ //将解压后的文件转换成GeoJson格式
public static List<String> shpToGeoJson(File zipFile) throws IOException {
FeatureJSON fjson = new FeatureJSON();
- JSONObject geoJsonObject=new JSONObject();
- geoJsonObject.put("type","FeatureCollection");
- List<String> strings=new ArrayList<>();
+ JSONObject geoJsonObject = new JSONObject();
+ geoJsonObject.put("type", "FeatureCollection");
+ List<String> strings = new ArrayList<>();
try {
// 获取FeatureCollection
FeatureCollection collection = getFeatureCollectionByShpFile(zipFile);
FeatureIterator iterator = collection.features();
- List<JSONObject> array = new ArrayList<JSONObject>();
+ List<JSONObject> array = new ArrayList<JSONObject>();
//遍历feature转为json对象
while (iterator.hasNext()) {
SimpleFeature feature = (SimpleFeature) iterator.next();
@@ -91,10 +84,10 @@
}
iterator.close();
//添加到geojsonObject
- geoJsonObject.put("features",array);
+ geoJsonObject.put("features", array);
iterator.close();
- }catch (Exception e){
+ } catch (Exception e) {
throw e;
}
return strings;
--
Gitblit v1.9.3