|
@@ -3,38 +3,38 @@ package com.onemap.analyse.task;
|
|
|
import com.onemap.analyse.domain.FzxzDTO;
|
|
|
import com.onemap.analyse.domain.FzxzXzyzDTO;
|
|
|
import com.onemap.common.core.web.domain.StatusMsg;
|
|
|
+import com.supermap.analyst.spatialanalyst.OverlayAnalyst;
|
|
|
+import com.supermap.analyst.spatialanalyst.OverlayAnalystParameter;
|
|
|
import com.supermap.data.*;
|
|
|
import com.supermap.data.conversion.DataImport;
|
|
|
import com.supermap.data.conversion.ImportMode;
|
|
|
+import com.supermap.data.conversion.ImportResult;
|
|
|
import com.supermap.data.conversion.ImportSettingSHP;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 辅助规划选址,通过超图iObject分析
|
|
|
*/
|
|
|
@Component
|
|
|
public class FzxzPlanSchedule {
|
|
|
- //工作空间
|
|
|
- private static Workspace mWorkspace = null;
|
|
|
- //数据源
|
|
|
- private static Datasource datasource = null;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param fzxzDTO 选址任务
|
|
|
* @param xzyzList 选址因子
|
|
|
*/
|
|
|
public static void startPlan(FzxzDTO fzxzDTO, List<FzxzXzyzDTO> xzyzList) {
|
|
|
- StatusMsg statusMsg = setWorkspace();
|
|
|
+ StatusMsg statusMsg = new StatusMsg();
|
|
|
//初始化失败返回结果
|
|
|
if (fzxzDTO.getFwlx() == 1) {
|
|
|
+ //statusMsg = setWorkspace();
|
|
|
// 绘制
|
|
|
String geoWkt = fzxzDTO.getXzfw();
|
|
|
Geometry geometry = Toolkit.WKTToGeometry(geoWkt);
|
|
|
- statusMsg = siteAnalysis(geometry);
|
|
|
+ statusMsg = siteAnalysis(geometry, xzyzList);
|
|
|
//拿到图层
|
|
|
} else if (fzxzDTO.getFwlx() == 2) {
|
|
|
// shp文件
|
|
@@ -42,116 +42,146 @@ public class FzxzPlanSchedule {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static StatusMsg setWorkspace() {
|
|
|
+ //private static StatusMsg setWorkspace() {
|
|
|
+ // StatusMsg statusMsg = new StatusMsg();
|
|
|
+ //
|
|
|
+ // DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
+ // info.setEngineType(EngineType.PGGIS);
|
|
|
+ // //TODO:配置信息放到配置文件中
|
|
|
+ // info.setServer("192.168.60.202:5432");
|
|
|
+ // info.setDatabase("real3d");
|
|
|
+ // info.setUser("postgres");
|
|
|
+ // info.setPassword("postgres");
|
|
|
+ //
|
|
|
+ // Workspace mWorkspace = new Workspace();
|
|
|
+ // Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
+ //
|
|
|
+ // if (datasource == null) {
|
|
|
+ // statusMsg.setMsg("创建数据源失败");
|
|
|
+ // statusMsg.setB(false);
|
|
|
+ // return statusMsg;
|
|
|
+ // }
|
|
|
+ // return statusMsg;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //TODO:这里暂时导入不成功
|
|
|
+ private static StatusMsg siteAnalysis(String filePath) {
|
|
|
StatusMsg statusMsg = new StatusMsg();
|
|
|
|
|
|
+ //1.创建数据源
|
|
|
DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
info.setEngineType(EngineType.PGGIS);
|
|
|
//TODO:配置信息放到配置文件中
|
|
|
info.setServer("192.168.60.202:5432");
|
|
|
- info.setDatabase("real3d");
|
|
|
+ info.setDatabase("plan");
|
|
|
info.setUser("postgres");
|
|
|
info.setPassword("postgres");
|
|
|
|
|
|
- mWorkspace = new Workspace();
|
|
|
- datasource = mWorkspace.getDatasources().open(info);
|
|
|
+ Workspace mWorkspace = new Workspace();
|
|
|
+ Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
|
|
|
if (datasource == null) {
|
|
|
statusMsg.setMsg("创建数据源失败");
|
|
|
statusMsg.setB(false);
|
|
|
return statusMsg;
|
|
|
}
|
|
|
- return statusMsg;
|
|
|
- }
|
|
|
-
|
|
|
- //TODO:这里暂时导入不成功
|
|
|
- private static StatusMsg siteAnalysis(String filePath) {
|
|
|
- StatusMsg statusMsg = new StatusMsg();
|
|
|
-
|
|
|
- int i0 = datasource.getDatasets().getCount();
|
|
|
- String[] datasetNames = datasource.getDatasets().getDatasetNames();
|
|
|
|
|
|
+ //2.导入数据
|
|
|
// 构建目标文件路径
|
|
|
- // 获取当前工作目录,即项目根目录
|
|
|
String projectRootDir = System.getProperty("user.dir");
|
|
|
String targetFilePath = projectRootDir + File.separator + "data" + File.separator + "shp" + File.separator + "xzqh.shp";
|
|
|
|
|
|
//导入shp文件
|
|
|
+ String originalRegions = "original_regions";
|
|
|
ImportSettingSHP importSettingSHP = new ImportSettingSHP();
|
|
|
- //同名会覆盖
|
|
|
importSettingSHP.setImportMode(ImportMode.OVERWRITE);
|
|
|
- //设置文件路径
|
|
|
importSettingSHP.setSourceFilePath(targetFilePath);
|
|
|
//设置需要导入的数据编码类型,因为有中文字段,所以用ASCII编码
|
|
|
- //importSettingSHP.setSourceFileCharset(Charset.ANSI);
|
|
|
- importSettingSHP.setTargetDatasetName("vector_plan");
|
|
|
+ importSettingSHP.setSourceFileCharset(Charset.ANSI);
|
|
|
+ importSettingSHP.setTargetDatasetName(originalRegions);
|
|
|
|
|
|
//设置要导入的目标数据源
|
|
|
importSettingSHP.setTargetDatasource(datasource);
|
|
|
DataImport dataImport = new DataImport();
|
|
|
dataImport.getImportSettings().add(importSettingSHP);
|
|
|
- dataImport.run();
|
|
|
|
|
|
- int i1 = datasource.getDatasets().getCount();
|
|
|
+ ImportResult result = dataImport.run();
|
|
|
+ if (result.getFailedSettings().length != 0) {
|
|
|
+ statusMsg.setMsg("数据导入失败");
|
|
|
+ statusMsg.setB(false);
|
|
|
+ return statusMsg;
|
|
|
+ }
|
|
|
+ //DatasetVector dataset = (DatasetVector) datasource.getDatasets().get("vector_plan");
|
|
|
+ //int all1Size = dataset.getAllFeatures().size();
|
|
|
+ //System.out.println("");
|
|
|
+
|
|
|
|
|
|
- DatasetVector dataset = (DatasetVector) datasource.getDatasets().get("vector_plan");
|
|
|
- int index = dataset.getID(); //获得导入后相应的数据集的序号
|
|
|
- String name = dataset.getName();
|
|
|
- int all1Size = dataset.getAllFeatures().size();
|
|
|
- System.out.println("");
|
|
|
+ //3.圈选数据
|
|
|
+ //源数据
|
|
|
+ DatasourceConnectionInfo infoReal3d = new DatasourceConnectionInfo();
|
|
|
+ infoReal3d.setEngineType(EngineType.PGGIS);
|
|
|
+ //TODO:配置信息放到配置文件中
|
|
|
+ infoReal3d.setServer("192.168.60.202:5432");
|
|
|
+ infoReal3d.setDatabase("real3d");
|
|
|
+ infoReal3d.setUser("postgres");
|
|
|
+ infoReal3d.setPassword("postgres");
|
|
|
|
|
|
- ////源数据
|
|
|
+ Workspace real3dWorkspace = new Workspace();
|
|
|
+ Datasource real3dResource = real3dWorkspace.getDatasources().open(infoReal3d);
|
|
|
+ DatasetVector ghdkaDataset = (DatasetVector) real3dResource.getDatasets().get("vector_GHDKA");
|
|
|
+
|
|
|
+ //1.打开数据源
|
|
|
//Datasets datasets = datasource.getDatasets();
|
|
|
//DatasetVector ghdkaDataset = (DatasetVector) datasets.get("vector_GHDKA");
|
|
|
- ////圈选区域
|
|
|
- //DatasetVector planDataset = (DatasetVector) datasets.get("vector_plan_dataset");
|
|
|
- //
|
|
|
- //int all0Size = ghdkaDataset.getAllFeatures().size();
|
|
|
- //int all1Size = planDataset.getAllFeatures().size();
|
|
|
- //
|
|
|
- //// 设置查询参数
|
|
|
- //QueryParameter parameter = new QueryParameter();
|
|
|
- ////where 条件
|
|
|
- ////parameter.setAttributeFilter("SmID<100");
|
|
|
- //parameter.setCursorType(CursorType.STATIC);
|
|
|
- //parameter.setSpatialQueryMode(SpatialQueryMode.CONTAIN);
|
|
|
- //parameter.setSpatialQueryObject(planDataset);
|
|
|
- //// 进行查询
|
|
|
- //Recordset recordsetRes = ghdkaDataset.query(parameter);
|
|
|
- //
|
|
|
- //for (Map.Entry<Integer, Feature> entry : recordsetRes.getAllFeatures().entrySet()) {
|
|
|
- // Integer key = entry.getKey();
|
|
|
- // Feature feature = entry.getValue();
|
|
|
- // String wktRes = Toolkit.GeometryToWKT(feature.getGeometry());
|
|
|
- // System.out.println(wktRes);
|
|
|
- //}
|
|
|
- // 释放工作空间占有的资源
|
|
|
- //ghdkaDataset.close();
|
|
|
+
|
|
|
+
|
|
|
+ //圈选区域
|
|
|
+ Datasets datasets = datasource.getDatasets();
|
|
|
+ DatasetVector originalDataset = (DatasetVector) datasets.get(originalRegions);
|
|
|
+
|
|
|
+ QueryParameter parameter = new QueryParameter();
|
|
|
+ parameter.setCursorType(CursorType.STATIC);
|
|
|
+ parameter.setSpatialQueryMode(SpatialQueryMode.CONTAIN);
|
|
|
+ parameter.setSpatialQueryObject(originalDataset);
|
|
|
+ // 进行查询
|
|
|
+ Recordset recordsetRes = ghdkaDataset.query(parameter);
|
|
|
+ int featureCount = recordsetRes.getAllFeatures().size();
|
|
|
+
|
|
|
+ //4.创建圈选后的数据集,并存储数据
|
|
|
+ DatasetVector dataset_result = (DatasetVector) datasets.createFromTemplate(datasets.getAvailableDatasetName("new_GHDKA"), ghdkaDataset);
|
|
|
+ // 将空间查询结果追加到新建的数据集中
|
|
|
+ dataset_result.append(recordsetRes);
|
|
|
+
|
|
|
+
|
|
|
+ //释放工作空间占有的资源
|
|
|
+ info.dispose();
|
|
|
mWorkspace.dispose();
|
|
|
return statusMsg;
|
|
|
}
|
|
|
|
|
|
|
|
|
// 选址分析
|
|
|
- private static StatusMsg siteAnalysis(Geometry geometry) {
|
|
|
+ private static StatusMsg siteAnalysis(Geometry geometry, List<FzxzXzyzDTO> xzyzList) {
|
|
|
StatusMsg statusMsg = new StatusMsg();
|
|
|
+ //1.创建数据源
|
|
|
+ DatasourceConnectionInfo info = new DatasourceConnectionInfo();
|
|
|
+ info.setEngineType(EngineType.PGGIS);
|
|
|
+ //TODO:配置信息放到配置文件中
|
|
|
+ info.setServer("192.168.60.202:5432");
|
|
|
+ info.setDatabase("real3d");
|
|
|
+ info.setUser("postgres");
|
|
|
+ info.setPassword("postgres");
|
|
|
|
|
|
- Datasets datasets = datasource.getDatasets();
|
|
|
- ////TODO:临时代码,输出数据集名称
|
|
|
- //int dbCount = datasource.getDatasets().getCount();
|
|
|
- //for (int i = 0; i < dbCount; i++) {
|
|
|
- // Dataset da = datasource.getDatasets().get(i);
|
|
|
- // System.out.println(da.getName());
|
|
|
- //}
|
|
|
-
|
|
|
+ Workspace mWorkspace = new Workspace();
|
|
|
+ Datasource datasource = mWorkspace.getDatasources().open(info);
|
|
|
|
|
|
+ //1.打开数据源
|
|
|
+ Datasets datasets = datasource.getDatasets();
|
|
|
DatasetVector ghdkaDataset = (DatasetVector) datasets.get("vector_GHDKA");
|
|
|
- int allSize = ghdkaDataset.getAllFeatures().size();
|
|
|
+ //int allSize = ghdkaDataset.getAllFeatures().size();
|
|
|
|
|
|
- // 设置查询参数
|
|
|
+ //2.空间数据圈选
|
|
|
QueryParameter parameter = new QueryParameter();
|
|
|
- //where 条件
|
|
|
- //parameter.setAttributeFilter("SmID<100");
|
|
|
parameter.setCursorType(CursorType.STATIC);
|
|
|
parameter.setSpatialQueryMode(SpatialQueryMode.CONTAIN);
|
|
|
parameter.setSpatialQueryObject(geometry);
|
|
@@ -159,11 +189,8 @@ public class FzxzPlanSchedule {
|
|
|
Recordset recordsetRes = ghdkaDataset.query(parameter);
|
|
|
int featureCount = recordsetRes.getAllFeatures().size();
|
|
|
|
|
|
- //创建圈选后的数据集
|
|
|
- // 以 dataset_world 为模板创建数据集
|
|
|
- DatasetVector dataset_result = (DatasetVector) datasets
|
|
|
- .createFromTemplate(datasets.getAvailableDatasetName("new_GHDKA"), ghdkaDataset);
|
|
|
-
|
|
|
+ //3.创建圈选后的数据集,并存储数据
|
|
|
+ DatasetVector dataset_result = (DatasetVector) datasets.createFromTemplate(datasets.getAvailableDatasetName("new_GHDKA"), ghdkaDataset);
|
|
|
// 将空间查询结果追加到新建的数据集中
|
|
|
dataset_result.append(recordsetRes);
|
|
|
|