网页版
This commit is contained in:
@ -29,7 +29,7 @@ public class GdalController {
|
|||||||
public void importDataStreamGzip(@Parameter(description = "矢量文件路径", required = true) @RequestParam("path") String path, HttpServletResponse response) throws IOException {
|
public void importDataStreamGzip(@Parameter(description = "矢量文件路径", required = true) @RequestParam("path") String path, HttpServletResponse response) throws IOException {
|
||||||
|
|
||||||
// 解析矢量文件、得到JSON数据
|
// 解析矢量文件、得到JSON数据
|
||||||
String jsonData = GdalUtil.readVectorToJson(path);
|
String jsonData = GdalUtil.readVectorToGeoJson(path);
|
||||||
|
|
||||||
// 设置响应头
|
// 设置响应头
|
||||||
String filename = URLEncoder.encode("data.gz", StandardCharsets.UTF_8);
|
String filename = URLEncoder.encode("data.gz", StandardCharsets.UTF_8);
|
||||||
|
|||||||
@ -237,6 +237,7 @@ public class IconLibraryController {
|
|||||||
params.add(fileSuffix);
|
params.add(fileSuffix);
|
||||||
params.add(file.getBytes());
|
params.add(file.getBytes());
|
||||||
params.add(LocalDateTime.now().toString());
|
params.add(LocalDateTime.now().toString());
|
||||||
|
System.out.println(insertSql);
|
||||||
|
|
||||||
SQLiteUtil.executeUpdate(iconPath, insertSql, params);
|
SQLiteUtil.executeUpdate(iconPath, insertSql, params);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,9 @@ public class SaTokenConfig implements WebMvcConfigurer {
|
|||||||
excludePathPatterns.add("/data/mbtiles/**");
|
excludePathPatterns.add("/data/mbtiles/**");
|
||||||
excludePathPatterns.add("/data/pak/**");
|
excludePathPatterns.add("/data/pak/**");
|
||||||
excludePathPatterns.add("/systemService/**");
|
excludePathPatterns.add("/systemService/**");
|
||||||
|
excludePathPatterns.add("/iconLibrary/data/icon/**");
|
||||||
|
excludePathPatterns.add("/militaryLibrary/data/military/**");
|
||||||
|
excludePathPatterns.add("/modelLibrary/data/**");
|
||||||
|
|
||||||
// 注册 Sa-Token 拦截器
|
// 注册 Sa-Token 拦截器
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> {
|
registry.addInterceptor(new SaInterceptor(handle -> {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.yj.earth.common.util;
|
|||||||
|
|
||||||
import org.gdal.gdal.gdal;
|
import org.gdal.gdal.gdal;
|
||||||
import org.gdal.ogr.*;
|
import org.gdal.ogr.*;
|
||||||
|
import org.gdal.osr.SpatialReference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -16,67 +17,82 @@ public class GdalUtil {
|
|||||||
gdal.AllRegister();
|
gdal.AllRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readVectorToJson(String filePath) {
|
/**
|
||||||
|
* 读取矢量文件并转换为标准GeoJSON格式
|
||||||
|
*/
|
||||||
|
public static String readVectorToGeoJson(String filePath) {
|
||||||
// 打开矢量文件
|
// 打开矢量文件
|
||||||
DataSource dataSource = ogr.Open(filePath);
|
DataSource dataSource = ogr.Open(filePath);
|
||||||
if (dataSource == null) {
|
if (dataSource == null) {
|
||||||
throw new RuntimeException("无法打开矢量文件: " + filePath);
|
throw new RuntimeException("无法打开矢量文件: " + filePath);
|
||||||
}
|
}
|
||||||
// 存储所有数据的Map
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
// 创建GeoJSON根对象 - FeatureCollection
|
||||||
// 获取图层数量
|
Map<String, Object> geoJson = new HashMap<>();
|
||||||
|
geoJson.put("type", "FeatureCollection");
|
||||||
|
|
||||||
|
// 存储所有要素
|
||||||
|
List<Map<String, Object>> features = new ArrayList<>();
|
||||||
|
geoJson.put("features", features);
|
||||||
|
|
||||||
|
// 获取所有图层
|
||||||
int layerCount = dataSource.GetLayerCount();
|
int layerCount = dataSource.GetLayerCount();
|
||||||
result.put("layerCount", layerCount);
|
|
||||||
// 存储所有图层数据
|
|
||||||
List<Map<String, Object>> layers = new ArrayList<>();
|
|
||||||
for (int i = 0; i < layerCount; i++) {
|
for (int i = 0; i < layerCount; i++) {
|
||||||
Layer layer = dataSource.GetLayer(i);
|
Layer layer = dataSource.GetLayer(i);
|
||||||
if (layer == null) continue;
|
if (layer == null) continue;
|
||||||
// 图层信息
|
|
||||||
Map<String, Object> layerData = new HashMap<>();
|
// 获取空间参考信息
|
||||||
layerData.put("layerName", layer.GetName());
|
SpatialReference srs = layer.GetSpatialRef();
|
||||||
layerData.put("featureCount", layer.GetFeatureCount());
|
if (srs != null && features.isEmpty()) { // 只添加一次CRS信息
|
||||||
|
Map<String, Object> crs = new HashMap<>();
|
||||||
|
Map<String, Object> crsProps = new HashMap<>();
|
||||||
|
crsProps.put("name", srs.GetAttrValue("AUTHORITY", 0) + ":" + srs.GetAttrValue("AUTHORITY", 1));
|
||||||
|
crs.put("type", "name");
|
||||||
|
crs.put("properties", crsProps);
|
||||||
|
geoJson.put("crs", crs);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取字段定义
|
// 获取字段定义
|
||||||
FeatureDefn featureDefn = layer.GetLayerDefn();
|
FeatureDefn featureDefn = layer.GetLayerDefn();
|
||||||
int fieldCount = featureDefn.GetFieldCount();
|
int fieldCount = featureDefn.GetFieldCount();
|
||||||
List<Map<String, Object>> fields = new ArrayList<>();
|
|
||||||
for (int j = 0; j < fieldCount; j++) {
|
|
||||||
FieldDefn fieldDefn = featureDefn.GetFieldDefn(j);
|
|
||||||
Map<String, Object> fieldInfo = new HashMap<>();
|
|
||||||
fieldInfo.put("name", fieldDefn.GetName());
|
|
||||||
fieldInfo.put("type", fieldDefn.GetFieldTypeName(fieldDefn.GetFieldType()));
|
|
||||||
fields.add(fieldInfo);
|
|
||||||
}
|
|
||||||
layerData.put("fields", fields);
|
|
||||||
// 读取所有要素
|
// 读取所有要素
|
||||||
List<Map<String, Object>> features = new ArrayList<>();
|
|
||||||
layer.ResetReading();
|
layer.ResetReading();
|
||||||
Feature feature;
|
Feature feature;
|
||||||
|
|
||||||
while ((feature = layer.GetNextFeature()) != null) {
|
while ((feature = layer.GetNextFeature()) != null) {
|
||||||
Map<String, Object> featureData = new HashMap<>();
|
// 创建Feature对象
|
||||||
|
Map<String, Object> featureObj = new HashMap<>();
|
||||||
|
featureObj.put("type", "Feature");
|
||||||
|
|
||||||
// 存储属性信息
|
// 存储属性信息
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
// 可以添加图层名称作为属性
|
||||||
|
properties.put("layerName", layer.GetName());
|
||||||
|
|
||||||
for (int j = 0; j < fieldCount; j++) {
|
for (int j = 0; j < fieldCount; j++) {
|
||||||
attributes.put(featureDefn.GetFieldDefn(j).GetName(), feature.GetFieldAsString(j));
|
String fieldName = featureDefn.GetFieldDefn(j).GetName();
|
||||||
|
properties.put(fieldName, feature.GetFieldAsString(j));
|
||||||
}
|
}
|
||||||
featureData.put("attributes", attributes);
|
featureObj.put("properties", properties);
|
||||||
// 存储几何信息
|
|
||||||
|
// 存储几何信息,转换为GeoJSON格式
|
||||||
Geometry geometry = feature.GetGeometryRef();
|
Geometry geometry = feature.GetGeometryRef();
|
||||||
if (geometry != null) {
|
if (geometry != null) {
|
||||||
featureData.put("geometryType", geometry.GetGeometryName());
|
|
||||||
featureData.put("wkt", geometry.ExportToWkt());
|
String geometryJson = geometry.ExportToJson();
|
||||||
|
Map<String, Object> geometryObj = JsonUtil.jsonToMap(geometryJson);
|
||||||
|
featureObj.put("geometry", geometryObj);
|
||||||
}
|
}
|
||||||
features.add(featureData);
|
|
||||||
feature.delete(); // 释放资源
|
features.add(featureObj);
|
||||||
|
feature.delete();
|
||||||
}
|
}
|
||||||
layerData.put("features", features);
|
|
||||||
layers.add(layerData);
|
|
||||||
}
|
}
|
||||||
result.put("layers", layers);
|
|
||||||
// 关闭数据源
|
// 关闭数据源
|
||||||
dataSource.delete();
|
dataSource.delete();
|
||||||
|
|
||||||
// 转换为JSON并返回
|
// 转换为JSON并返回
|
||||||
return JsonUtil.toJson(result);
|
return JsonUtil.toJson(geoJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -231,17 +231,13 @@ public class SQLiteConverter {
|
|||||||
String sourcePath = "F:\\公司通用模型库.model";
|
String sourcePath = "F:\\公司通用模型库.model";
|
||||||
// 目标数据库路径
|
// 目标数据库路径
|
||||||
String targetPath = "F:\\通用模型库.model";
|
String targetPath = "F:\\通用模型库.model";
|
||||||
|
|
||||||
System.out.println("开始数据库转换...");
|
System.out.println("开始数据库转换...");
|
||||||
System.out.println("源数据库: " + sourcePath);
|
System.out.println("源数据库: " + sourcePath);
|
||||||
System.out.println("目标数据库: " + targetPath);
|
System.out.println("目标数据库: " + targetPath);
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 创建转换器并执行转换
|
// 创建转换器并执行转换
|
||||||
SQLiteConverter converter = new SQLiteConverter(sourcePath, targetPath);
|
SQLiteConverter converter = new SQLiteConverter(sourcePath, targetPath);
|
||||||
converter.convert();
|
converter.convert();
|
||||||
|
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
double elapsedTime = (endTime - startTime) / 1000.0;
|
double elapsedTime = (endTime - startTime) / 1000.0;
|
||||||
System.out.printf("转换完成、耗时: %.2f秒%n", elapsedTime);
|
System.out.printf("转换完成、耗时: %.2f秒%n", elapsedTime);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import lombok.Data;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class IconVo extends Icon {
|
public class IconVo{
|
||||||
@Schema(description = "图标类型名称")
|
@Schema(description = "图标类型名称")
|
||||||
private String iconTypeName;
|
private String iconTypeName;
|
||||||
@Schema(description = "图标数据URL")
|
@Schema(description = "图标数据URL")
|
||||||
|
|||||||
Reference in New Issue
Block a user