|
@@ -3,10 +3,13 @@ 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.data.conversion.ImportSettingSHP;
|
|
|
import com.supermap.data.*;
|
|
|
+import com.supermap.data.conversion.DataImport;
|
|
|
+import com.supermap.data.conversion.ImportMode;
|
|
|
+import com.supermap.data.conversion.ImportSettingSHP;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -15,49 +18,125 @@ import java.util.Map;
|
|
|
*/
|
|
|
@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();
|
|
|
+ //初始化失败返回结果
|
|
|
if (fzxzDTO.getFwlx() == 1) {
|
|
|
// 绘制
|
|
|
String geoWkt = fzxzDTO.getXzfw();
|
|
|
Geometry geometry = Toolkit.WKTToGeometry(geoWkt);
|
|
|
- StatusMsg statusMsg = siteAnalysis(geometry);
|
|
|
+ statusMsg = siteAnalysis(geometry);
|
|
|
//拿到图层
|
|
|
} else if (fzxzDTO.getFwlx() == 2) {
|
|
|
// shp文件
|
|
|
-
|
|
|
- ImportSettingSHP importSettingSHP = new ImportSettingSHP();
|
|
|
-
|
|
|
+ statusMsg = siteAnalysis(fzxzDTO.getXzfw());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 选址分析
|
|
|
- private static StatusMsg siteAnalysis(Geometry geometry) {
|
|
|
+ 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);
|
|
|
+ mWorkspace = new Workspace();
|
|
|
+ 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();
|
|
|
+
|
|
|
+ // 构建目标文件路径
|
|
|
+ // 获取当前工作目录,即项目根目录
|
|
|
+ String projectRootDir = System.getProperty("user.dir");
|
|
|
+ String targetFilePath = projectRootDir + File.separator + "data" + File.separator + "shp" + File.separator + "xzqh.shp";
|
|
|
+
|
|
|
+ //导入shp文件
|
|
|
+ ImportSettingSHP importSettingSHP = new ImportSettingSHP();
|
|
|
+ //同名会覆盖
|
|
|
+ importSettingSHP.setImportMode(ImportMode.OVERWRITE);
|
|
|
+ //设置文件路径
|
|
|
+ importSettingSHP.setSourceFilePath(targetFilePath);
|
|
|
+ //设置需要导入的数据编码类型,因为有中文字段,所以用ASCII编码
|
|
|
+ //importSettingSHP.setSourceFileCharset(Charset.ANSI);
|
|
|
+ importSettingSHP.setTargetDatasetName("vector_plan");
|
|
|
+
|
|
|
+ //设置要导入的目标数据源
|
|
|
+ importSettingSHP.setTargetDatasource(datasource);
|
|
|
+ DataImport dataImport = new DataImport();
|
|
|
+ dataImport.getImportSettings().add(importSettingSHP);
|
|
|
+ dataImport.run();
|
|
|
+
|
|
|
+ int i1 = datasource.getDatasets().getCount();
|
|
|
+
|
|
|
+ DatasetVector dataset = (DatasetVector) datasource.getDatasets().get("vector_plan");
|
|
|
+ int index = dataset.getID(); //获得导入后相应的数据集的序号
|
|
|
+ String name = dataset.getName();
|
|
|
+ int all1Size = dataset.getAllFeatures().size();
|
|
|
+ System.out.println("");
|
|
|
+
|
|
|
+ ////源数据
|
|
|
+ //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();
|
|
|
+ mWorkspace.dispose();
|
|
|
+ return statusMsg;
|
|
|
+ }
|
|
|
|
|
|
- Datasets datasets = datasource.getDatasets();
|
|
|
|
|
|
+ // 选址分析
|
|
|
+ private static StatusMsg siteAnalysis(Geometry geometry) {
|
|
|
+ StatusMsg statusMsg = new StatusMsg();
|
|
|
+
|
|
|
+ Datasets datasets = datasource.getDatasets();
|
|
|
////TODO:临时代码,输出数据集名称
|
|
|
//int dbCount = datasource.getDatasets().getCount();
|
|
|
//for (int i = 0; i < dbCount; i++) {
|
|
@@ -80,15 +159,16 @@ public class FzxzPlanSchedule {
|
|
|
Recordset recordsetRes = ghdkaDataset.query(parameter);
|
|
|
int featureCount = recordsetRes.getAllFeatures().size();
|
|
|
|
|
|
- //recordsetRes.getAllFeatures().get(0).getGeometry();
|
|
|
+ //创建圈选后的数据集
|
|
|
+ // 以 dataset_world 为模板创建数据集
|
|
|
+ DatasetVector dataset_result = (DatasetVector) datasets
|
|
|
+ .createFromTemplate(datasets.getAvailableDatasetName("new_GHDKA"), ghdkaDataset);
|
|
|
+
|
|
|
+ // 将空间查询结果追加到新建的数据集中
|
|
|
+ dataset_result.append(recordsetRes);
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
// 释放工作空间占有的资源
|
|
|
+ dataset_result.close();
|
|
|
ghdkaDataset.close();
|
|
|
mWorkspace.dispose();
|
|
|
|