BenchmarkLandPrice_old.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. import { v4 as uuidv4 } from "uuid";
  2. import moment from "moment";
  3. import {
  4. cartesian3ToWGS84,
  5. mapQuery,
  6. flatten,
  7. mercator2lonLat,
  8. undergroundMode,
  9. } from "@/utils/MapHelper/MapHelper.js";
  10. import {
  11. area,
  12. intersect,
  13. polygon,
  14. point,
  15. midpoint,
  16. difference,
  17. } from "@turf/turf";
  18. const BenchmarkLandPrice = {
  19. /**
  20. * 基准地价分析
  21. * @param {*} BenchmarkLandPrice {
  22. ProjectScope: [],分析范围
  23. ProjectName: "",项目名称
  24. ConstructionUnit: "",建设单位
  25. imageBase64: [],输出图片
  26. }
  27. * @param {*} isOutputImg 是否输出范围图片 true false 如需输出图片,请确保要输出的范围已在屏幕正确认为
  28. * @param {*} Callback 回调
  29. */
  30. async calculateLandPrice(BenchmarkLandPrice, isOutputImg = false, Callback) {
  31. let GHDKList = await this.getGHDKs(BenchmarkLandPrice);
  32. await this.GetJZDJ(BenchmarkLandPrice, GHDKList);
  33. let data = await this.CalculateJZDJ(BenchmarkLandPrice, GHDKList);
  34. if (isOutputImg) {
  35. if (data && data.picBase64List) {
  36. var promise = scene.outputSceneToFile();
  37. Cesium.when(promise, function (base64data) {
  38. data.picBase64List.push(base64data);
  39. if (Callback) Callback(data);
  40. });
  41. } else {
  42. if (Callback) Callback(false);
  43. }
  44. } else {
  45. if (data) {
  46. if (Callback) Callback(data);
  47. } else {
  48. if (Callback) Callback(false);
  49. }
  50. }
  51. },
  52. /**
  53. * 查询区域内规划地块
  54. * @param {*} BenchmarkLandPrice 基准地价信息
  55. * @returns {*} 图层返回信息
  56. * {
  57. id: uuidv4(),
  58. layerInfo: layer,
  59. data: [],
  60. geometry: feature.geometry,
  61. }
  62. */
  63. async getGHDKs(BenchmarkLandPrice) {
  64. let featureDataList = [];
  65. //查询规划地块
  66. let layer = flatten(window.layerTree).find((item) => item.core == "003006");
  67. let points = BenchmarkLandPrice.ProjectScope;
  68. let geo = {
  69. id: 0,
  70. style: null,
  71. parts: [points.length],
  72. points: points,
  73. type: "REGION",
  74. prjCoordSys: {
  75. epsgCode: null,
  76. },
  77. };
  78. let queryByGeometryParameters = {
  79. getFeatureMode: "SPATIAL",
  80. datasetNames: [
  81. layer.date_server.dataSourceName + ":" + layer.date_server.datasetName,
  82. ],
  83. geometry: geo,
  84. spatialQueryMode: "INTERSECT",
  85. hasGeometry: "true",
  86. };
  87. let e = await mapQuery(
  88. layer.date_server.url + "/featureResults.json?returnContent=true",
  89. queryByGeometryParameters
  90. );
  91. if (e && e.totalCount > 0) {
  92. e.features.forEach((feature) => {
  93. let featureData = {
  94. id: uuidv4(),
  95. layerInfo: layer,
  96. data: [],
  97. geometry: feature.geometry,
  98. };
  99. feature.fieldNames.forEach((fieldName, i) => {
  100. let Field = e.datasetInfos
  101. ? e.datasetInfos[0].fieldInfos.find(
  102. (c) =>
  103. c.name &&
  104. c.name.toUpperCase() == fieldName.toUpperCase() &&
  105. c.name.toUpperCase().indexOf("SM") == -1
  106. )
  107. : null;
  108. if (Field) {
  109. featureData.data.push({
  110. label: fieldName,
  111. labelCN: Field ? Field.caption : fieldName,
  112. value: feature.fieldValues[i],
  113. });
  114. }
  115. });
  116. featureDataList.push(featureData);
  117. });
  118. }
  119. return featureDataList;
  120. },
  121. /**
  122. * 获取基准地价
  123. * @param {*} BenchmarkLandPrice
  124. * @param {*} GHDKList
  125. * @returns
  126. */
  127. async GetJZDJ(BenchmarkLandPrice, GHDKList) {
  128. for (let GHDKindex = 0; GHDKindex < GHDKList.length; GHDKindex++) {
  129. let GHDK = GHDKList[GHDKindex];
  130. GHDK.JZDJList = [];
  131. let KZXXGYDDM = GHDK.data.find((c) => c.label == "KZXXGYDDM");
  132. let landUseNatureRelation = flatten(window.landUseNatureRelation).find(
  133. (c) => {
  134. let GHDKType = c.GHDKType.find((a) =>
  135. KZXXGYDDM.value.startsWith(a.ydxzdl)
  136. );
  137. return GHDKType != null;
  138. }
  139. );
  140. if (landUseNatureRelation) {
  141. let layerinfos = landUseNatureRelation.layerinfo;
  142. for (let index = 0; index < layerinfos.length; index++) {
  143. let layerinfo = layerinfos[index];
  144. let layer = flatten(window.layerTree).find(
  145. (item) => item.core == layerinfo.layerCore
  146. );
  147. if (layer && layer.date_server && layer.date_server.url) {
  148. let points = BenchmarkLandPrice.ProjectScope;
  149. let geo = {
  150. id: 0,
  151. style: null,
  152. parts: [points.length],
  153. points: points,
  154. type: "REGION",
  155. prjCoordSys: {
  156. epsgCode: null,
  157. },
  158. };
  159. let queryByGeometryParameters = {
  160. getFeatureMode: "SPATIAL",
  161. datasetNames: [
  162. layer.date_server.dataSourceName +
  163. ":" +
  164. layer.date_server.datasetName,
  165. ],
  166. geometry: geo,
  167. spatialQueryMode: "INTERSECT",
  168. hasGeometry: "true",
  169. };
  170. let e = await mapQuery(
  171. layer.date_server.url + "/featureResults.json?returnContent=true",
  172. queryByGeometryParameters
  173. );
  174. if (e && e.totalCount > 0) {
  175. e.features.forEach((feature) => {
  176. let layerData = {
  177. id: uuidv4(),
  178. layerInfo: layerinfo,
  179. data: [],
  180. geometry: feature.geometry,
  181. };
  182. feature.fieldNames.forEach((fieldName, i) => {
  183. let Field = e.datasetInfos
  184. ? e.datasetInfos[0].fieldInfos.find(
  185. (c) =>
  186. c.name &&
  187. c.name.toUpperCase() == fieldName.toUpperCase() &&
  188. c.name.toUpperCase().indexOf("SM") == -1
  189. )
  190. : null;
  191. if (Field) {
  192. layerData.data.push({
  193. label: fieldName,
  194. labelCN: Field ? Field.caption : fieldName,
  195. value: feature.fieldValues[i],
  196. });
  197. }
  198. });
  199. GHDK.JZDJList.push(layerData);
  200. });
  201. }
  202. } else {
  203. console.log(
  204. "服务编码【" + layerinfo.layerCore + "】配置不正确,请检查后重试"
  205. );
  206. }
  207. }
  208. } else {
  209. console.log(KZXXGYDDM + "未配置当前土地用途,请联系管理员添加");
  210. }
  211. }
  212. },
  213. /**
  214. * 计算基准地价
  215. */
  216. async CalculateJZDJ(BenchmarkLandPrice, GHDKList) {
  217. //转换成超图格式面
  218. let HZgeometry = {
  219. partTopo: [1],
  220. parts: [BenchmarkLandPrice.ProjectScope.length],
  221. points: BenchmarkLandPrice.ProjectScope,
  222. };
  223. // 循环规划地块区域信息
  224. GHDKList.forEach((GHDK) => {
  225. GHDK.fromData = [];
  226. GHDK.JZDJList.forEach((JZDJ) => {
  227. let area = this.calculateIntersectArea(
  228. GHDK.geometry,
  229. JZDJ.geometry,
  230. HZgeometry
  231. );
  232. if (Number(area) > 0) {
  233. let fromData = { data: JZDJ.data, area: Number(area) / 666.66 };
  234. //土地级别
  235. let tdjb = JZDJ.data.find(
  236. (c) => c.label == JZDJ.layerInfo.tdjbField
  237. ).value;
  238. fromData.tdjb = tdjb;
  239. //单价
  240. let dj = JZDJ.data.find(
  241. (c) => c.label == JZDJ.layerInfo.ydlxPriceField
  242. ).value;
  243. fromData.dj = (Number(dj) * 666.66) / 10000;
  244. //占用面积地价
  245. fromData.zdj = Number(area * dj) / 10000;
  246. fromData.geometry = JZDJ.geometry;
  247. GHDK.fromData.push(fromData);
  248. }
  249. });
  250. });
  251. //计算分析面积
  252. let fxzmj = this.CalculateAnalysisArea(BenchmarkLandPrice);
  253. //总地价
  254. let zdj = 0;
  255. //参与地价计算的面积(规划地块+绘制范围+地价地块范围三者交集)
  256. let jszmj = 0;
  257. //规划地块详细地价
  258. let ghdkDetailedDjList = [];
  259. GHDKList.forEach((GHDK) => {
  260. let ghdkDetailed = {};
  261. ghdkDetailed.id = GHDK.id;
  262. ghdkDetailed.geometry = GHDK.geometry;
  263. ghdkDetailed.data = GHDK.data;
  264. ghdkDetailed.ghyt = GHDK.data.find((c) => c.label == "KZXXGYDMC").value;
  265. ghdkDetailed.dkbm = GHDK.data.find((c) => c.label == "DKBM").value;
  266. //占用土地
  267. ghdkDetailed.zytdList = GHDK.fromData;
  268. ghdkDetailedDjList.push(ghdkDetailed);
  269. GHDK.fromData.forEach((fromData) => {
  270. zdj += fromData.zdj;
  271. jszmj += fromData.area;
  272. });
  273. });
  274. ghdkDetailedDjList = ghdkDetailedDjList.filter(
  275. (c) => c.zytdList && c.zytdList.length > 0
  276. );
  277. return {
  278. projectName: BenchmarkLandPrice.ProjectName, //项目名称
  279. analysisDate: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"), //分析时间
  280. // projectType: BenchmarkLandPrice.ProjectType, //项目类型
  281. buildUnit: BenchmarkLandPrice.ConstructionUnit, //建设单位
  282. analysisArea: fxzmj, //分析面积(亩)
  283. ParticipationArea: jszmj, //参与地价计算的面积(亩)
  284. totalLandPrice: zdj, //总地价(万元) 总地价预估合计
  285. ghdkDetailedDjList: ghdkDetailedDjList, //规划地块详细地价
  286. picBase64List: [], //图片集 分析范围
  287. };
  288. },
  289. /**
  290. * 计算分析面积
  291. * @param {*} BenchmarkLandPrice 基准地价信息
  292. * @returns {number} 分析总面积
  293. */
  294. CalculateAnalysisArea(BenchmarkLandPrice) {
  295. let fxzmj = 0;
  296. let points = BenchmarkLandPrice.ProjectScope;
  297. let DataPs = points.map((item) => [item.x, item.y]);
  298. if (DataPs.length > 0) {
  299. if (
  300. JSON.stringify(DataPs[0]) != JSON.stringify(DataPs[DataPs.length - 1])
  301. ) {
  302. DataPs.push(DataPs[0]);
  303. }
  304. debugger;
  305. let polygonPs = polygon([DataPs]);
  306. let sdsd = area(polygonPs);
  307. let areaPs = area(polygonPs) * window.earthRadius;
  308. fxzmj = Number(areaPs / 666.66).toFixed(2);
  309. }
  310. return fxzmj;
  311. },
  312. /**
  313. * 计算两个面的交集面积
  314. * @param Points1
  315. * @param Points2
  316. * @param Points3
  317. */
  318. calculateIntersectArea(Points1, Points2, Points3) {
  319. var geometry1;
  320. var geometry2;
  321. var geometry3;
  322. if (Points1) {
  323. geometry1 = this.AssemblySurface(Points1);
  324. }
  325. if (Points2) {
  326. geometry2 = this.AssemblySurface(Points2);
  327. }
  328. if (Points3) {
  329. geometry3 = this.AssemblySurface(Points3);
  330. }
  331. let areaPs;
  332. if (geometry1 && geometry2) {
  333. areaPs = intersect(geometry1, geometry2);
  334. }
  335. if (areaPs && geometry3) {
  336. areaPs = intersect(areaPs, geometry3);
  337. }
  338. if (areaPs) {
  339. let areadifference = area(areaPs) * window.earthRadius;
  340. return Number(areadifference.toFixed(2));
  341. } else {
  342. return 0;
  343. }
  344. },
  345. /**
  346. * 组装带洞和不带洞的面
  347. * @param geometry 超图返回的图形数组
  348. */
  349. AssemblySurface(geometry) {
  350. let point3ds = [];
  351. let pointholes = [];
  352. let startindex = 0;
  353. for (let index = 0; index < geometry.parts.length; index++) {
  354. let thisps = [];
  355. let endindex = startindex + geometry.parts[index];
  356. let geometryPoints = geometry.points.slice(startindex, endindex);
  357. for (
  358. let pointindex = 0;
  359. pointindex < geometryPoints.length;
  360. pointindex++
  361. ) {
  362. let point = geometryPoints[pointindex];
  363. thisps.push([point.x, point.y]);
  364. }
  365. if (geometry.partTopo[index] === 1) {
  366. point3ds.push(thisps);
  367. } else {
  368. pointholes.push(thisps);
  369. }
  370. startindex = endindex;
  371. }
  372. // 主多边形
  373. var mainPolygon = polygon(point3ds);
  374. // 岛洞多边形
  375. var holePolygon = polygon(pointholes);
  376. // 计算差集 得到有导洞的图形
  377. var getdifference = difference(mainPolygon, holePolygon);
  378. return getdifference;
  379. },
  380. };
  381. /**
  382. * 基准地价分析
  383. */
  384. export default BenchmarkLandPrice;