|
@@ -1,22 +1,30 @@
|
|
|
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 org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
@RestController
|
|
|
@RequestMapping("/test/data")
|
|
|
public class TestData {
|
|
|
-
|
|
|
- private static Workspace mWorkspace;
|
|
|
-
|
|
|
-
|
|
|
@GetMapping("/point")
|
|
|
public RequestResult list(String param) {
|
|
|
- System.out.println(System.getProperty("java.library.path"));
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
@@ -25,28 +33,44 @@ public class TestData {
|
|
|
info.setEngineType(EngineType.PGGIS);
|
|
|
// info.setEngineType(EngineType.POSTGRESQL);
|
|
|
info.setServer("192.168.100.252:5432");
|
|
|
- info.setDatabase("test_data");
|
|
|
+ info.setDatabase("test_data1");
|
|
|
info.setUser("postgres");
|
|
|
info.setPassword("postgres");
|
|
|
- info.setAlias("PGGISSource");
|
|
|
-
|
|
|
- mWorkspace = new Workspace();
|
|
|
+// info.setAlias("PGGISSource");
|
|
|
|
|
|
- Datasource datasource = mWorkspace.getDatasources().create(info);
|
|
|
+ Workspace mWorkspace = new Workspace();
|
|
|
+ Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
|
|
|
if (datasource != null) {
|
|
|
System.out.println("创建数据源成功");
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
System.out.println("创建数据源失败");
|
|
|
}
|
|
|
int dbCount = datasource.getDatasets().getCount();
|
|
|
|
|
|
Datasets datasets = datasource.getDatasets();
|
|
|
|
|
|
- Dataset dtHebei=datasets.get("he_bei");
|
|
|
- Dataset dtPolygon1=datasets.get("polygon1");
|
|
|
+ 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);
|
|
|
|
|
|
- //sde数据库带空间属性的表叫图层,因此图层跟表类似
|
|
|
- String layerName = "polygon1";
|
|
|
+ // 释放工作空间占有的资源
|
|
|
+ mWorkspace.dispose();
|
|
|
}
|
|
|
}
|