网页版
This commit is contained in:
		| @ -28,6 +28,9 @@ public class SaTokenConfig implements WebMvcConfigurer { | ||||
|         excludePathPatterns.add("/data/mbtiles/**"); | ||||
|         excludePathPatterns.add("/data/pak/**"); | ||||
|         excludePathPatterns.add("/systemService/**"); | ||||
|         excludePathPatterns.add("/iconLibrary/data/icon/**"); | ||||
|         excludePathPatterns.add("/militaryLibrary/data/military/**"); | ||||
|         excludePathPatterns.add("/modelLibrary/data/**"); | ||||
|  | ||||
|         // 注册 Sa-Token 拦截器 | ||||
|         registry.addInterceptor(new SaInterceptor(handle -> { | ||||
|  | ||||
| @ -2,6 +2,7 @@ package com.yj.earth.common.util; | ||||
|  | ||||
| import org.gdal.gdal.gdal; | ||||
| import org.gdal.ogr.*; | ||||
| import org.gdal.osr.SpatialReference; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| @ -16,67 +17,82 @@ public class GdalUtil { | ||||
|         gdal.AllRegister(); | ||||
|     } | ||||
|  | ||||
|     public static String readVectorToJson(String filePath) { | ||||
|     /** | ||||
|      * 读取矢量文件并转换为标准GeoJSON格式 | ||||
|      */ | ||||
|     public static String readVectorToGeoJson(String filePath) { | ||||
|         // 打开矢量文件 | ||||
|         DataSource dataSource = ogr.Open(filePath); | ||||
|         if (dataSource == null) { | ||||
|             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(); | ||||
|         result.put("layerCount", layerCount); | ||||
|         // 存储所有图层数据 | ||||
|         List<Map<String, Object>> layers = new ArrayList<>(); | ||||
|         for (int i = 0; i < layerCount; i++) { | ||||
|             Layer layer = dataSource.GetLayer(i); | ||||
|             if (layer == null) continue; | ||||
|             // 图层信息 | ||||
|             Map<String, Object> layerData = new HashMap<>(); | ||||
|             layerData.put("layerName", layer.GetName()); | ||||
|             layerData.put("featureCount", layer.GetFeatureCount()); | ||||
|  | ||||
|             // 获取空间参考信息 | ||||
|             SpatialReference srs = layer.GetSpatialRef(); | ||||
|             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(); | ||||
|             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(); | ||||
|             Feature feature; | ||||
|  | ||||
|             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++) { | ||||
|                     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(); | ||||
|                 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(); | ||||
|  | ||||
|         // 转换为JSON并返回 | ||||
|         return JsonUtil.toJson(result); | ||||
|         return JsonUtil.toJson(geoJson); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -231,17 +231,13 @@ public class SQLiteConverter { | ||||
|         String sourcePath = "F:\\公司通用模型库.model"; | ||||
|         // 目标数据库路径 | ||||
|         String targetPath = "F:\\通用模型库.model"; | ||||
|  | ||||
|         System.out.println("开始数据库转换..."); | ||||
|         System.out.println("源数据库: " + sourcePath); | ||||
|         System.out.println("目标数据库: " + targetPath); | ||||
|  | ||||
|         long startTime = System.currentTimeMillis(); | ||||
|  | ||||
|         // 创建转换器并执行转换 | ||||
|         SQLiteConverter converter = new SQLiteConverter(sourcePath, targetPath); | ||||
|         converter.convert(); | ||||
|  | ||||
|         long endTime = System.currentTimeMillis(); | ||||
|         double elapsedTime = (endTime - startTime) / 1000.0; | ||||
|         System.out.printf("转换完成、耗时: %.2f秒%n", elapsedTime); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 ZZX9599
					ZZX9599