推送
This commit is contained in:
@ -34,7 +34,7 @@ public class CodeUtil {
|
||||
}
|
||||
|
||||
// 传入需要生成代码的表名
|
||||
Generation("pbf_info");
|
||||
Generation("device");
|
||||
}
|
||||
|
||||
public static void Generation(String... tableName) {
|
||||
|
||||
@ -8,6 +8,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -15,34 +16,22 @@ import java.util.Map;
|
||||
|
||||
import static org.gdal.ogr.ogrConstants.*;
|
||||
|
||||
/**
|
||||
* GDAL地理数据转JSON工具类
|
||||
*/
|
||||
import org.gdal.gdal.gdal;
|
||||
import org.gdal.ogr.*;
|
||||
import org.gdal.osr.SpatialReference;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* GDAL地理数据转JSON工具类
|
||||
*/
|
||||
public class GdalJsonConverter {
|
||||
|
||||
static {
|
||||
// 初始化GDAL
|
||||
// 动态获取项目根目录下的lib文件夹路径
|
||||
String projectRoot = System.getProperty("user.dir");
|
||||
|
||||
// 拼接lib目录路径(项目根目录/lib)
|
||||
String projLibPath = projectRoot + File.separator + "lib";
|
||||
|
||||
// 设置PROJ库路径(指向包含proj.db的lib目录)
|
||||
gdal.SetConfigOption("PROJ_LIB", projLibPath);
|
||||
gdal.AllRegister();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将地理数据文件转换为指定结构的JSON
|
||||
* @param filePath 文件绝对路径
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String convertToJson(String filePath) {
|
||||
return convertToJson(filePath, "");
|
||||
@ -50,11 +39,8 @@ public class GdalJsonConverter {
|
||||
|
||||
/**
|
||||
* 将地理数据文件转换为指定结构的JSON
|
||||
* @param filePath 文件绝对路径
|
||||
* @param targetCrs 目标坐标系(如:"EPSG:4326"),为空则不转换
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String convertToJson(String filePath, String targetCrs) {
|
||||
private static String convertToJson(String filePath, String targetCrs) {
|
||||
try {
|
||||
// 打开数据源
|
||||
DataSource dataSource = ogr.Open(filePath, 0);
|
||||
@ -80,7 +66,7 @@ public class GdalJsonConverter {
|
||||
result.put("list", listArray);
|
||||
dataSource.delete();
|
||||
|
||||
return result.toString(2); // 缩进2个空格,美化输出
|
||||
return result.toString(2);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("转换失败: " + e.getMessage(), e);
|
||||
@ -88,7 +74,7 @@ public class GdalJsonConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建FeatureCollection对象
|
||||
* 创建 FeatureCollection 对象
|
||||
*/
|
||||
private static JSONObject createFeatureCollection(Layer layer, String layerName, String targetCrs) throws JSONException {
|
||||
JSONObject featureCollection = new JSONObject();
|
||||
@ -108,10 +94,10 @@ public class GdalJsonConverter {
|
||||
// 重置图层读取位置
|
||||
layer.ResetReading();
|
||||
|
||||
// 获取图层定义,用于字段信息
|
||||
// 获取图层定义、用于字段信息
|
||||
FeatureDefn layerDefn = layer.GetLayerDefn();
|
||||
|
||||
// 如果需要坐标转换,创建坐标转换对象
|
||||
// 如果需要坐标转换、创建坐标转换对象
|
||||
SpatialReference sourceSrs = layer.GetSpatialRef();
|
||||
SpatialReference targetSrs = null;
|
||||
CoordinateTransformation coordTrans = null;
|
||||
@ -164,7 +150,7 @@ public class GdalJsonConverter {
|
||||
return proj4.trim();
|
||||
}
|
||||
|
||||
// 如果PROJ4为空,尝试获取WKT
|
||||
// 如果PROJ4为空、尝试获取WKT
|
||||
String wkt = srs.ExportToWkt();
|
||||
if (wkt != null && !wkt.trim().isEmpty()) {
|
||||
return wkt.trim();
|
||||
@ -186,8 +172,7 @@ public class GdalJsonConverter {
|
||||
/**
|
||||
* 创建单个Feature对象
|
||||
*/
|
||||
private static JSONObject createFeature(Feature feature, FeatureDefn layerDefn,
|
||||
CoordinateTransformation coordTrans, boolean transformCoords) throws JSONException {
|
||||
private static JSONObject createFeature(Feature feature, FeatureDefn layerDefn, CoordinateTransformation coordTrans, boolean transformCoords) throws JSONException {
|
||||
JSONObject featureObj = new JSONObject();
|
||||
featureObj.put("type", "Feature");
|
||||
|
||||
@ -220,7 +205,7 @@ public class GdalJsonConverter {
|
||||
geomToUse = transformedGeom;
|
||||
} catch (Exception e) {
|
||||
System.err.println("坐标转换失败: " + e.getMessage());
|
||||
// 如果转换失败,使用原始几何
|
||||
// 如果转换失败、使用原始几何
|
||||
geomToUse = geometry;
|
||||
}
|
||||
}
|
||||
@ -233,7 +218,7 @@ public class GdalJsonConverter {
|
||||
geomToUse.delete();
|
||||
}
|
||||
} else {
|
||||
// 如果没有几何信息,创建空的MultiPolygon
|
||||
// 如果没有几何信息、创建空的MultiPolygon
|
||||
featureObj.put("geometry", createEmptyMultiPolygon());
|
||||
}
|
||||
|
||||
@ -452,11 +437,9 @@ public class GdalJsonConverter {
|
||||
layerInfo.put("name", layer.GetName());
|
||||
layerInfo.put("featureCount", layer.GetFeatureCount());
|
||||
layerInfo.put("geometryType", ogr.GeometryTypeToName(layer.GetGeomType()));
|
||||
|
||||
// 添加坐标系信息
|
||||
String crs = getLayerCrs(layer);
|
||||
layerInfo.put("crs", crs != null ? crs : "未知");
|
||||
|
||||
layers.add(layerInfo);
|
||||
}
|
||||
info.put("layers", layers);
|
||||
|
||||
@ -171,11 +171,11 @@ public class SdkUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("sdk配置文件中未配置server.port");
|
||||
log.error("sdk 配置文件中未配置 server.port");
|
||||
} catch (IOException e) {
|
||||
log.error("读取sdk配置文件失败", e);
|
||||
log.error("读取 sdk 配置文件失败", e);
|
||||
} catch (ClassCastException e) {
|
||||
log.error("sdk配置文件中server.port格式错误、应为数字类型", e);
|
||||
log.error("sdk 配置文件中 server.port 格式错误、应为数字类型", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user