|
@@ -1,13 +1,13 @@
|
|
|
package com.onemap.apply.controller.data;
|
|
|
|
|
|
import com.onemap.common.core.web.domain.RequestResult;
|
|
|
-import com.supermap.analyst.spatialanalyst.OverlayAnalyst;
|
|
|
-import com.supermap.analyst.spatialanalyst.OverlayAnalystParameter;
|
|
|
-import com.supermap.data.*;
|
|
|
-import com.supermap.data.conversion.DataExport;
|
|
|
-import com.supermap.data.conversion.ExportSetting;
|
|
|
-import com.supermap.data.conversion.ExportSettingGeoJson;
|
|
|
-import com.supermap.data.conversion.FileType;
|
|
|
+// import com.supermap.analyst.spatialanalyst.OverlayAnalyst;
|
|
|
+// import com.supermap.analyst.spatialanalyst.OverlayAnalystParameter;
|
|
|
+// import com.supermap.data.*;
|
|
|
+// import com.supermap.data.conversion.DataExport;
|
|
|
+// import com.supermap.data.conversion.ExportSetting;
|
|
|
+// import com.supermap.data.conversion.ExportSettingGeoJson;
|
|
|
+// import com.supermap.data.conversion.FileType;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -18,116 +18,116 @@ import java.util.Date;
|
|
|
@RestController
|
|
|
@RequestMapping("/test/data")
|
|
|
public class TestData {
|
|
|
- @GetMapping("/point")
|
|
|
- public RequestResult list(String param) {
|
|
|
- System.out.println("执行开始时间: " + new Date());
|
|
|
- long startTime = System.nanoTime();
|
|
|
-
|
|
|
- createDatabaseSource();
|
|
|
-
|
|
|
- System.out.println("执行结束时间: " + new Date());
|
|
|
- long endTime = System.nanoTime();
|
|
|
- long duration = (endTime - startTime) / 1000000; // 将纳秒转换为毫秒
|
|
|
- System.out.println("函数执行时间: " + duration + " 毫秒");
|
|
|
-
|
|
|
- return RequestResult.success("查询成功", null);
|
|
|
- }
|
|
|
-
|
|
|
- // 做union合并分析
|
|
|
- private static void createDatabaseSource() {
|
|
|
- DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
- info.setEngineType(EngineType.PGGIS);
|
|
|
- info.setServer("192.168.100.202:5432");
|
|
|
- info.setDatabase("test_data1");
|
|
|
- info.setUser("postgres");
|
|
|
- info.setPassword("postgres");
|
|
|
-
|
|
|
- Workspace mWorkspace = new Workspace();
|
|
|
- Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
-
|
|
|
- if (datasource != null) {
|
|
|
- System.out.println("创建数据源成功");
|
|
|
- } else {
|
|
|
- System.out.println("创建数据源失败");
|
|
|
- }
|
|
|
- int dbCount = datasource.getDatasets().getCount();
|
|
|
-
|
|
|
- Datasets datasets = datasource.getDatasets();
|
|
|
-
|
|
|
- DatasetVector dtHebei = (DatasetVector) datasets.get("hebei");
|
|
|
- DatasetVector dtPolygon1 = (DatasetVector) datasets.get("polygon1");
|
|
|
-
|
|
|
- // 创建一个面矢量数据集,用于存储合并分析返回的结果
|
|
|
- String resultDatasetUnionName = datasource.getDatasets().getAvailableDatasetName("result_union");
|
|
|
- DatasetVectorInfo datasetvectorInfoUnion = new DatasetVectorInfo();
|
|
|
- datasetvectorInfoUnion.setType(DatasetType.REGION);
|
|
|
- datasetvectorInfoUnion.setName(resultDatasetUnionName);
|
|
|
- datasetvectorInfoUnion.setEncodeType(EncodeType.NONE);
|
|
|
- DatasetVector resultDatasetUnion = datasource.getDatasets().create(datasetvectorInfoUnion);
|
|
|
-
|
|
|
- // 设置叠加分析参数
|
|
|
- OverlayAnalystParameter overlayAnalystParamUnion = new OverlayAnalystParameter();
|
|
|
- overlayAnalystParamUnion.setOperationRetainedFields(new String[]{"name"});//第二数据集保留字段
|
|
|
- overlayAnalystParamUnion.setSourceRetainedFields(new String[]{"adcode"});//第一数据集保留字段
|
|
|
- overlayAnalystParamUnion.setTolerance(0.0000011074);
|
|
|
-
|
|
|
- // 调用合并叠加分析方法实合并分析
|
|
|
- OverlayAnalyst.union(dtHebei, dtPolygon1, resultDatasetUnion, overlayAnalystParamUnion);
|
|
|
-
|
|
|
- // 释放工作空间占有的资源
|
|
|
- mWorkspace.dispose();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @GetMapping("/geojson")
|
|
|
- public RequestResult getJson() {
|
|
|
- DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
- info.setEngineType(EngineType.PGGIS);
|
|
|
- info.setServer("192.168.60.202:5432");
|
|
|
- info.setDatabase("test_data1");
|
|
|
- info.setUser("postgres");
|
|
|
- info.setPassword("postgres");
|
|
|
-
|
|
|
- Workspace mWorkspace = new Workspace();
|
|
|
- Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
-
|
|
|
- if (datasource != null) {
|
|
|
- System.out.println("创建数据源成功");
|
|
|
- } else {
|
|
|
- System.out.println("创建数据源失败");
|
|
|
- return RequestResult.error("创建数据源失败");
|
|
|
- }
|
|
|
-
|
|
|
- Datasets datasets = datasource.getDatasets();
|
|
|
- DatasetVector dtHebeiVertical = (DatasetVector) datasets.get("hebei_city");
|
|
|
-
|
|
|
-
|
|
|
- ExportSettingGeoJson exportSettingGeoJson = new ExportSettingGeoJson();
|
|
|
- exportSettingGeoJson.setOverwrite(true);
|
|
|
-
|
|
|
- ExportSetting exportSetting = new ExportSetting();
|
|
|
- exportSetting.setOverwrite(true);
|
|
|
-
|
|
|
- // 获取当前工作目录,即项目根目录
|
|
|
- String projectRootDir = System.getProperty("user.dir");
|
|
|
- try {
|
|
|
- File file = new File(projectRootDir, "data");
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdir();
|
|
|
- }
|
|
|
- // 构建目标文件路径
|
|
|
- String targetFilePath = projectRootDir + File.separator + "data" + File.separator + "hebei_city.geojson";
|
|
|
-
|
|
|
- exportSettingGeoJson.setTargetFileType(FileType.GEOJSON);
|
|
|
- exportSettingGeoJson.setTargetFilePath(targetFilePath);
|
|
|
- exportSettingGeoJson.setSourceData(dtHebeiVertical);
|
|
|
-
|
|
|
- DataExport dataExport = new DataExport();
|
|
|
- dataExport.getExportSettings().add(exportSettingGeoJson);
|
|
|
- dataExport.run();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return RequestResult.success("数据创建成功", null);
|
|
|
- }
|
|
|
+ // @GetMapping("/point")
|
|
|
+ // public RequestResult list(String param) {
|
|
|
+ // System.out.println("执行开始时间: " + new Date());
|
|
|
+ // long startTime = System.nanoTime();
|
|
|
+ //
|
|
|
+ // createDatabaseSource();
|
|
|
+ //
|
|
|
+ // System.out.println("执行结束时间: " + new Date());
|
|
|
+ // long endTime = System.nanoTime();
|
|
|
+ // long duration = (endTime - startTime) / 1000000; // 将纳秒转换为毫秒
|
|
|
+ // System.out.println("函数执行时间: " + duration + " 毫秒");
|
|
|
+ //
|
|
|
+ // return RequestResult.success("查询成功", null);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 做union合并分析
|
|
|
+ // private static void createDatabaseSource() {
|
|
|
+ // DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
+ // info.setEngineType(EngineType.PGGIS);
|
|
|
+ // info.setServer("192.168.100.202:5432");
|
|
|
+ // info.setDatabase("test_data1");
|
|
|
+ // info.setUser("postgres");
|
|
|
+ // info.setPassword("postgres");
|
|
|
+ //
|
|
|
+ // Workspace mWorkspace = new Workspace();
|
|
|
+ // Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
+ //
|
|
|
+ // if (datasource != null) {
|
|
|
+ // System.out.println("创建数据源成功");
|
|
|
+ // } else {
|
|
|
+ // System.out.println("创建数据源失败");
|
|
|
+ // }
|
|
|
+ // int dbCount = datasource.getDatasets().getCount();
|
|
|
+ //
|
|
|
+ // Datasets datasets = datasource.getDatasets();
|
|
|
+ //
|
|
|
+ // DatasetVector dtHebei = (DatasetVector) datasets.get("hebei");
|
|
|
+ // DatasetVector dtPolygon1 = (DatasetVector) datasets.get("polygon1");
|
|
|
+ //
|
|
|
+ // // 创建一个面矢量数据集,用于存储合并分析返回的结果
|
|
|
+ // String resultDatasetUnionName = datasource.getDatasets().getAvailableDatasetName("result_union");
|
|
|
+ // DatasetVectorInfo datasetvectorInfoUnion = new DatasetVectorInfo();
|
|
|
+ // datasetvectorInfoUnion.setType(DatasetType.REGION);
|
|
|
+ // datasetvectorInfoUnion.setName(resultDatasetUnionName);
|
|
|
+ // datasetvectorInfoUnion.setEncodeType(EncodeType.NONE);
|
|
|
+ // DatasetVector resultDatasetUnion = datasource.getDatasets().create(datasetvectorInfoUnion);
|
|
|
+ //
|
|
|
+ // // 设置叠加分析参数
|
|
|
+ // OverlayAnalystParameter overlayAnalystParamUnion = new OverlayAnalystParameter();
|
|
|
+ // overlayAnalystParamUnion.setOperationRetainedFields(new String[]{"name"});//第二数据集保留字段
|
|
|
+ // overlayAnalystParamUnion.setSourceRetainedFields(new String[]{"adcode"});//第一数据集保留字段
|
|
|
+ // overlayAnalystParamUnion.setTolerance(0.0000011074);
|
|
|
+ //
|
|
|
+ // // 调用合并叠加分析方法实合并分析
|
|
|
+ // OverlayAnalyst.union(dtHebei, dtPolygon1, resultDatasetUnion, overlayAnalystParamUnion);
|
|
|
+ //
|
|
|
+ // // 释放工作空间占有的资源
|
|
|
+ // mWorkspace.dispose();
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // @GetMapping("/geojson")
|
|
|
+ // public RequestResult getJson() {
|
|
|
+ // DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
+ // info.setEngineType(EngineType.PGGIS);
|
|
|
+ // info.setServer("192.168.60.202:5432");
|
|
|
+ // info.setDatabase("test_data1");
|
|
|
+ // info.setUser("postgres");
|
|
|
+ // info.setPassword("postgres");
|
|
|
+ //
|
|
|
+ // Workspace mWorkspace = new Workspace();
|
|
|
+ // Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
+ //
|
|
|
+ // if (datasource != null) {
|
|
|
+ // System.out.println("创建数据源成功");
|
|
|
+ // } else {
|
|
|
+ // System.out.println("创建数据源失败");
|
|
|
+ // return RequestResult.error("创建数据源失败");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Datasets datasets = datasource.getDatasets();
|
|
|
+ // DatasetVector dtHebeiVertical = (DatasetVector) datasets.get("hebei_city");
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // ExportSettingGeoJson exportSettingGeoJson = new ExportSettingGeoJson();
|
|
|
+ // exportSettingGeoJson.setOverwrite(true);
|
|
|
+ //
|
|
|
+ // ExportSetting exportSetting = new ExportSetting();
|
|
|
+ // exportSetting.setOverwrite(true);
|
|
|
+ //
|
|
|
+ // // 获取当前工作目录,即项目根目录
|
|
|
+ // String projectRootDir = System.getProperty("user.dir");
|
|
|
+ // try {
|
|
|
+ // File file = new File(projectRootDir, "data");
|
|
|
+ // if (!file.exists()) {
|
|
|
+ // file.mkdir();
|
|
|
+ // }
|
|
|
+ // // 构建目标文件路径
|
|
|
+ // String targetFilePath = projectRootDir + File.separator + "data" + File.separator + "hebei_city.geojson";
|
|
|
+ //
|
|
|
+ // exportSettingGeoJson.setTargetFileType(FileType.GEOJSON);
|
|
|
+ // exportSettingGeoJson.setTargetFilePath(targetFilePath);
|
|
|
+ // exportSettingGeoJson.setSourceData(dtHebeiVertical);
|
|
|
+ //
|
|
|
+ // DataExport dataExport = new DataExport();
|
|
|
+ // dataExport.getExportSettings().add(exportSettingGeoJson);
|
|
|
+ // dataExport.run();
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // e.printStackTrace();
|
|
|
+ // }
|
|
|
+ // return RequestResult.success("数据创建成功", null);
|
|
|
+ // }
|
|
|
}
|