FzxzPlanSchedule.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. package com.onemap.analyse.task;
  2. import com.onemap.analyse.domain.FzxzDTO;
  3. import com.onemap.analyse.domain.FzxzXzyzDTO;
  4. import com.onemap.common.core.web.domain.StatusMsg;
  5. // import com.supermap.data.*;
  6. // import com.supermap.data.conversion.DataImport;
  7. // import com.supermap.data.conversion.ImportMode;
  8. // import com.supermap.data.conversion.ImportResult;
  9. // import com.supermap.data.conversion.ImportSettingSHP;
  10. import org.springframework.stereotype.Component;
  11. import java.io.File;
  12. import java.util.List;
  13. /**
  14. * 辅助规划选址,通过超图iObject分析
  15. */
  16. @Component
  17. public class FzxzPlanSchedule {
  18. private static String dbUrl = "127.0.0.1:5432";
  19. private static String dbName = "real";
  20. private static String dbUser = "postgres";
  21. private static String dbPwd = "postgis";
  22. /**
  23. * @param fzxzDTO 选址任务
  24. * @param xzyzList 选址因子
  25. */
  26. // public static void startPlan(FzxzDTO fzxzDTO, List<FzxzXzyzDTO> xzyzList) {
  27. // StatusMsg statusMsg = new StatusMsg();
  28. // // setWorkspace();
  29. // // 初始化失败返回结果
  30. // if (fzxzDTO.getFwlx() == 1) {
  31. // // 绘制
  32. // String geoWkt = fzxzDTO.getXzfw();
  33. // Geometry geometry = Toolkit.WKTToGeometry(geoWkt);
  34. // statusMsg = siteAnalysis(geometry, xzyzList);
  35. // // 拿到图层
  36. // } else if (fzxzDTO.getFwlx() == 2) {
  37. // // shp文件
  38. // statusMsg = siteAnalysis(fzxzDTO.getXzfw());
  39. // }
  40. // }
  41. //
  42. // private static StatusMsg setWorkspace() {
  43. // StatusMsg statusMsg = new StatusMsg();
  44. //
  45. // DatasourceConnectionInfo info = new DatasourceConnectionInfo();
  46. // info.setEngineType(EngineType.PGGIS);
  47. // // TODO:配置信息放到配置文件中
  48. // info.setServer(dbUrl);
  49. // info.setDatabase(dbName);
  50. // info.setUser(dbUser);
  51. // info.setPassword(dbPwd);
  52. //
  53. // Workspace mWorkspace = new Workspace();
  54. // Datasource datasource = mWorkspace.getDatasources().create(info);
  55. //
  56. // if (datasource == null) {
  57. // statusMsg.setMsg("创建数据源失败");
  58. // statusMsg.setB(false);
  59. // return statusMsg;
  60. // }
  61. // return statusMsg;
  62. // }
  63. //
  64. // // TODO:这里暂时导入不成功
  65. // private static StatusMsg siteAnalysis(String filePath) {
  66. // StatusMsg statusMsg = new StatusMsg();
  67. //
  68. // // 1.创建数据源
  69. // DatasourceConnectionInfo info = new DatasourceConnectionInfo();
  70. // info.setEngineType(EngineType.PGGIS);
  71. // // TODO:配置信息放到配置文件中
  72. // info.setServer(dbUrl);
  73. // info.setDatabase(dbName);
  74. // info.setUser(dbUser);
  75. // info.setPassword(dbPwd);
  76. //
  77. // Workspace mWorkspace = new Workspace();
  78. // Datasource datasource = mWorkspace.getDatasources().open(info);
  79. //
  80. // if (datasource == null) {
  81. // statusMsg.setMsg("创建数据源失败");
  82. // statusMsg.setB(false);
  83. // return statusMsg;
  84. // }
  85. //
  86. // // 2.导入数据
  87. // // 构建目标文件路径
  88. // String projectRootDir = System.getProperty("user.dir");
  89. // String targetFilePath = projectRootDir + File.separator + "data" + File.separator + "shp" + File.separator + "xzqh.shp";
  90. //
  91. // // 导入shp文件
  92. // String originalRegions = "original_regions";
  93. // ImportSettingSHP importSettingSHP = new ImportSettingSHP();
  94. // importSettingSHP.setImportMode(ImportMode.OVERWRITE);
  95. // importSettingSHP.setSourceFilePath(targetFilePath);
  96. // // 设置需要导入的数据编码类型,因为有中文字段,所以用ASCII编码
  97. // importSettingSHP.setSourceFileCharset(Charset.ANSI);
  98. // importSettingSHP.setTargetDatasetName(originalRegions);
  99. //
  100. // // 设置要导入的目标数据源
  101. // importSettingSHP.setTargetDatasource(datasource);
  102. // DataImport dataImport = new DataImport();
  103. // dataImport.getImportSettings().add(importSettingSHP);
  104. //
  105. // ImportResult result = dataImport.run();
  106. // if (result.getFailedSettings().length != 0) {
  107. // statusMsg.setMsg("数据导入失败");
  108. // statusMsg.setB(false);
  109. // return statusMsg;
  110. // }
  111. //
  112. // // 3.圈选数据
  113. // // 源数据
  114. // DatasourceConnectionInfo infoReal3d = new DatasourceConnectionInfo();
  115. // infoReal3d.setEngineType(EngineType.PGGIS);
  116. // // TODO:配置信息放到配置文件中
  117. // infoReal3d.setServer(dbUrl);
  118. // infoReal3d.setDatabase(dbName);
  119. // infoReal3d.setUser(dbUser);
  120. // infoReal3d.setPassword(dbPwd);
  121. //
  122. // Workspace real3dWorkspace = new Workspace();
  123. // Datasource real3dResource = real3dWorkspace.getDatasources().open(infoReal3d);
  124. // String[] names = real3dResource.getDatasets().getDatasetNames();
  125. // DatasetVector ghdkaDataset = (DatasetVector) real3dResource.getDatasets().get("vector_GHDKA");
  126. //
  127. // // 圈选区域
  128. // Datasets datasets = datasource.getDatasets();
  129. // DatasetVector originalDataset = (DatasetVector) datasets.get(originalRegions);
  130. //
  131. // QueryParameter parameter = new QueryParameter();
  132. // parameter.setCursorType(CursorType.STATIC);
  133. // parameter.setSpatialQueryMode(SpatialQueryMode.CONTAIN);
  134. // parameter.setSpatialQueryObject(originalDataset);
  135. // // 进行查询
  136. // Recordset recordsetRes = ghdkaDataset.query(parameter);
  137. // int featureCount = recordsetRes.getAllFeatures().size();
  138. //
  139. // // 4.创建圈选后的数据集,并存储数据
  140. // DatasetVector dataset_result = (DatasetVector) datasets.createFromTemplate(datasets.getAvailableDatasetName("new_GHDKA"), ghdkaDataset);
  141. // // 将空间查询结果追加到新建的数据集中
  142. // dataset_result.append(recordsetRes);
  143. //
  144. // // 释放工作空间占有的资源
  145. // infoReal3d.dispose();
  146. // real3dWorkspace.dispose();
  147. //
  148. // info.dispose();
  149. // mWorkspace.dispose();
  150. // return statusMsg;
  151. // }
  152. //
  153. //
  154. // // 选址分析
  155. // private static StatusMsg siteAnalysis(Geometry geometry, List<FzxzXzyzDTO> xzyzList) {
  156. // StatusMsg statusMsg = new StatusMsg();
  157. // // 1.创建数据源
  158. // DatasourceConnectionInfo info = new DatasourceConnectionInfo();
  159. // info.setEngineType(EngineType.PGGIS);
  160. // // info.setEngineType(EngineType);
  161. // // TODO:配置信息放到配置文件中
  162. // info.setServer(dbUrl);
  163. // info.setDatabase(dbName);
  164. // info.setUser(dbUser);
  165. // info.setPassword(dbPwd);
  166. //
  167. // Workspace mWorkspace = new Workspace();
  168. // Datasource datasource = mWorkspace.getDatasources().open(info);
  169. //
  170. // // 1.打开数据源
  171. // Datasets datasets = datasource.getDatasets();
  172. // DatasetVector ghdkaDataset = (DatasetVector) datasets.get("vector_GHDKA");
  173. // // int allSize = ghdkaDataset.getAllFeatures().size();
  174. //
  175. // // 2.空间数据圈选
  176. // QueryParameter parameter = new QueryParameter();
  177. // parameter.setCursorType(CursorType.STATIC);
  178. // parameter.setSpatialQueryMode(SpatialQueryMode.CONTAIN);
  179. // parameter.setSpatialQueryObject(geometry);
  180. // // 进行查询
  181. // Recordset recordsetRes = ghdkaDataset.query(parameter);
  182. // int featureCount = recordsetRes.getAllFeatures().size();
  183. //
  184. // // 3.创建圈选后的数据集,并存储数据
  185. // DatasetVector dataset_result = (DatasetVector) datasets.createFromTemplate(datasets.getAvailableDatasetName("new_GHDKA"), ghdkaDataset);
  186. // // 将空间查询结果追加到新建的数据集中
  187. // dataset_result.append(recordsetRes);
  188. //
  189. // // 释放工作空间占有的资源
  190. // dataset_result.close();
  191. // ghdkaDataset.close();
  192. // mWorkspace.dispose();
  193. //
  194. // return statusMsg;
  195. // }
  196. }