From 6d02d0adce5004ef244fc8e4f0186ed922b20e36 Mon Sep 17 00:00:00 2001
From: zrj <646384940@qq.com>
Date: Fri, 08 Nov 2024 20:02:07 +0800
Subject: [PATCH] 新增shp 文件导入,数据关联公司
---
src/main/java/org/springblade/common/utils/ShapeFileUtil.java | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/springblade/common/utils/ShapeFileUtil.java b/src/main/java/org/springblade/common/utils/ShapeFileUtil.java
index efcb2aa..3dd65ac 100644
--- a/src/main/java/org/springblade/common/utils/ShapeFileUtil.java
+++ b/src/main/java/org/springblade/common/utils/ShapeFileUtil.java
@@ -44,14 +44,15 @@
String fileName,
String geomType,
String saveFolder) {
+ String path = saveFolder + "/" + fileName;
//创建保存shp文件夹
- File dir = new File(saveFolder);
+ File dir = new File(path);
if (!dir.exists()) {
FileUtil.mkdir(dir);
}
//shp文件路径
String shpFileName = fileName + ".shp";
- String fileUrl = saveFolder + shpFileName;
+ String fileUrl = path+ "/" + shpFileName;
File file = new File(fileUrl);
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = null;
@@ -73,7 +74,6 @@
String geomProperty = "the_geom";
String idProperty = "ID";
String nameProperty = "name";
- String descriptionProperty = "desc";
//设置图形类型
if ("Polygon".equals(geomType)) {
@@ -94,7 +94,6 @@
//设置对应属性类型
tb.add(idProperty, String.class);
tb.add(nameProperty, String.class);
- tb.add(descriptionProperty, String.class);
//设置默认geometry
tb.setDefaultGeometry(geomProperty);
@@ -111,11 +110,11 @@
//属性赋值 geometry要赋值wkt格式的
feature.setAttribute(geomProperty, new WKTReader().read((MapUtil.getStr(map, "geometry"))));
feature.setAttribute(idProperty, MapUtil.getStr(map, idProperty));
- feature.setAttribute(nameProperty, MapUtil.getStr(map, "名称"));
- String description = MapUtil.getStr(map, "描述");
- if (CharSequenceUtil.isNotBlank(description)) {
- feature.setAttribute(descriptionProperty, description);
- }
+ feature.setAttribute(nameProperty, MapUtil.getStr(map, nameProperty));
+// String description = MapUtil.getStr(map, "描述");
+// if (CharSequenceUtil.isNotBlank(description)) {
+// feature.setAttribute(descriptionProperty, description);
+// }
}
writer.write();
} catch (IOException | FactoryException | ParseException e) {
@@ -207,8 +206,12 @@
shpDTO.put("type",json.getJSONObject("geometry").getString("type"));
}
// 名称
- if (json.getJSONObject("properties").get("name")!= null) {
- shpDTO.put("name",json.getJSONObject("properties").getString("name"));
+ if (json.getJSONObject("properties").get("Name")!= null) {
+ shpDTO.put("name",json.getJSONObject("properties").getString("Name"));
+ }
+ // 所属公司名称
+ if (json.getJSONObject("properties").get("name_1")!= null) {
+ shpDTO.put("firmName",json.getJSONObject("properties").getString("name_1"));
}
dtoList.add(shpDTO);
} catch (NumberFormatException e) {
--
Gitblit v1.9.3