123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- import { v4 as uuidv4 } from "uuid";
- import moment from "moment";
- import {
- cartesian3ToWGS84,
- mapQuery,
- flatten,
- mercator2lonLat,
- undergroundMode,
- } from "@/utils/MapHelper/MapHelper.js";
- import {
- area,
- intersect,
- polygon,
- point,
- midpoint,
- difference,
- } from "@turf/turf";
- const BenchmarkLandPrice = {
- /**
- * 基准地价分析
- * @param {*} BenchmarkLandPrice {
- ProjectScope: [],分析范围
- ProjectName: "",项目名称
- ConstructionUnit: "",建设单位
- imageBase64: [],输出图片
- }
- * @param {*} isOutputImg 是否输出范围图片 true false 如需输出图片,请确保要输出的范围已在屏幕正确认为
- * @param {*} Callback 回调
- */
- async calculateLandPrice(BenchmarkLandPrice, isOutputImg = false, Callback) {
- let GHDKList = await this.getGHDKs(BenchmarkLandPrice);
- await this.GetJZDJ(BenchmarkLandPrice, GHDKList);
- let data = await this.CalculateJZDJ(BenchmarkLandPrice, GHDKList);
- if (isOutputImg) {
- if (data && data.picBase64List) {
- var promise = scene.outputSceneToFile();
- Cesium.when(promise, function (base64data) {
- data.picBase64List.push(base64data);
- if (Callback) Callback(data);
- });
- } else {
- if (Callback) Callback(false);
- }
- } else {
- if (data) {
- if (Callback) Callback(data);
- } else {
- if (Callback) Callback(false);
- }
- }
- },
- /**
- * 查询区域内规划地块
- * @param {*} BenchmarkLandPrice 基准地价信息
- * @returns {*} 图层返回信息
- * {
- id: uuidv4(),
- layerInfo: layer,
- data: [],
- geometry: feature.geometry,
- }
- */
- async getGHDKs(BenchmarkLandPrice) {
- let featureDataList = [];
- //查询规划地块
- let layer = flatten(window.layerTree).find((item) => item.core == "003006");
- let points = BenchmarkLandPrice.ProjectScope;
- let geo = {
- id: 0,
- style: null,
- parts: [points.length],
- points: points,
- type: "REGION",
- prjCoordSys: {
- epsgCode: null,
- },
- };
- let queryByGeometryParameters = {
- getFeatureMode: "SPATIAL",
- datasetNames: [
- layer.date_server.dataSourceName + ":" + layer.date_server.datasetName,
- ],
- geometry: geo,
- spatialQueryMode: "INTERSECT",
- hasGeometry: "true",
- };
- let e = await mapQuery(
- layer.date_server.url + "/featureResults.json?returnContent=true",
- queryByGeometryParameters
- );
- if (e && e.totalCount > 0) {
- e.features.forEach((feature) => {
- let featureData = {
- id: uuidv4(),
- layerInfo: layer,
- data: [],
- geometry: feature.geometry,
- };
- feature.fieldNames.forEach((fieldName, i) => {
- let Field = e.datasetInfos
- ? e.datasetInfos[0].fieldInfos.find(
- (c) =>
- c.name &&
- c.name.toUpperCase() == fieldName.toUpperCase() &&
- c.name.toUpperCase().indexOf("SM") == -1
- )
- : null;
- if (Field) {
- featureData.data.push({
- label: fieldName,
- labelCN: Field ? Field.caption : fieldName,
- value: feature.fieldValues[i],
- });
- }
- });
- featureDataList.push(featureData);
- });
- }
- return featureDataList;
- },
- /**
- * 获取基准地价
- * @param {*} BenchmarkLandPrice
- * @param {*} GHDKList
- * @returns
- */
- async GetJZDJ(BenchmarkLandPrice, GHDKList) {
- for (let GHDKindex = 0; GHDKindex < GHDKList.length; GHDKindex++) {
- let GHDK = GHDKList[GHDKindex];
- GHDK.JZDJList = [];
- let KZXXGYDDM = GHDK.data.find((c) => c.label == "KZXXGYDDM");
- let landUseNatureRelation = flatten(window.landUseNatureRelation).find(
- (c) => {
- let GHDKType = c.GHDKType.find((a) =>
- KZXXGYDDM.value.startsWith(a.ydxzdl)
- );
- return GHDKType != null;
- }
- );
- if (landUseNatureRelation) {
- let layerinfos = landUseNatureRelation.layerinfo;
- for (let index = 0; index < layerinfos.length; index++) {
- let layerinfo = layerinfos[index];
- let layer = flatten(window.layerTree).find(
- (item) => item.core == layerinfo.layerCore
- );
- if (layer && layer.date_server && layer.date_server.url) {
- let points = BenchmarkLandPrice.ProjectScope;
- let geo = {
- id: 0,
- style: null,
- parts: [points.length],
- points: points,
- type: "REGION",
- prjCoordSys: {
- epsgCode: null,
- },
- };
- let queryByGeometryParameters = {
- getFeatureMode: "SPATIAL",
- datasetNames: [
- layer.date_server.dataSourceName +
- ":" +
- layer.date_server.datasetName,
- ],
- geometry: geo,
- spatialQueryMode: "INTERSECT",
- hasGeometry: "true",
- };
- let e = await mapQuery(
- layer.date_server.url + "/featureResults.json?returnContent=true",
- queryByGeometryParameters
- );
- if (e && e.totalCount > 0) {
- e.features.forEach((feature) => {
- let layerData = {
- id: uuidv4(),
- layerInfo: layerinfo,
- data: [],
- geometry: feature.geometry,
- };
- feature.fieldNames.forEach((fieldName, i) => {
- let Field = e.datasetInfos
- ? e.datasetInfos[0].fieldInfos.find(
- (c) =>
- c.name &&
- c.name.toUpperCase() == fieldName.toUpperCase() &&
- c.name.toUpperCase().indexOf("SM") == -1
- )
- : null;
- if (Field) {
- layerData.data.push({
- label: fieldName,
- labelCN: Field ? Field.caption : fieldName,
- value: feature.fieldValues[i],
- });
- }
- });
- GHDK.JZDJList.push(layerData);
- });
- }
- } else {
- console.log(
- "服务编码【" + layerinfo.layerCore + "】配置不正确,请检查后重试"
- );
- }
- }
- } else {
- console.log(KZXXGYDDM + "未配置当前土地用途,请联系管理员添加");
- }
- }
- },
- /**
- * 计算基准地价
- */
- async CalculateJZDJ(BenchmarkLandPrice, GHDKList) {
- //转换成超图格式面
- let HZgeometry = {
- partTopo: [1],
- parts: [BenchmarkLandPrice.ProjectScope.length],
- points: BenchmarkLandPrice.ProjectScope,
- };
- // 循环规划地块区域信息
- GHDKList.forEach((GHDK) => {
- GHDK.fromData = [];
- GHDK.JZDJList.forEach((JZDJ) => {
- let area = this.calculateIntersectArea(
- GHDK.geometry,
- JZDJ.geometry,
- HZgeometry
- );
- if (Number(area) > 0) {
- let fromData = { data: JZDJ.data, area: Number(area) / 666.66 };
- //土地级别
- let tdjb = JZDJ.data.find(
- (c) => c.label == JZDJ.layerInfo.tdjbField
- ).value;
- fromData.tdjb = tdjb;
- //单价
- let dj = JZDJ.data.find(
- (c) => c.label == JZDJ.layerInfo.ydlxPriceField
- ).value;
- fromData.dj = (Number(dj) * 666.66) / 10000;
- //占用面积地价
- fromData.zdj = Number(area * dj) / 10000;
- fromData.geometry = JZDJ.geometry;
- GHDK.fromData.push(fromData);
- }
- });
- });
- //计算分析面积
- let fxzmj = this.CalculateAnalysisArea(BenchmarkLandPrice);
- //总地价
- let zdj = 0;
- //参与地价计算的面积(规划地块+绘制范围+地价地块范围三者交集)
- let jszmj = 0;
- //规划地块详细地价
- let ghdkDetailedDjList = [];
- GHDKList.forEach((GHDK) => {
- let ghdkDetailed = {};
- ghdkDetailed.id = GHDK.id;
- ghdkDetailed.geometry = GHDK.geometry;
- ghdkDetailed.data = GHDK.data;
- ghdkDetailed.ghyt = GHDK.data.find((c) => c.label == "KZXXGYDMC").value;
- ghdkDetailed.dkbm = GHDK.data.find((c) => c.label == "DKBM").value;
- //占用土地
- ghdkDetailed.zytdList = GHDK.fromData;
- ghdkDetailedDjList.push(ghdkDetailed);
- GHDK.fromData.forEach((fromData) => {
- zdj += fromData.zdj;
- jszmj += fromData.area;
- });
- });
- ghdkDetailedDjList = ghdkDetailedDjList.filter(
- (c) => c.zytdList && c.zytdList.length > 0
- );
- return {
- projectName: BenchmarkLandPrice.ProjectName, //项目名称
- analysisDate: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"), //分析时间
- // projectType: BenchmarkLandPrice.ProjectType, //项目类型
- buildUnit: BenchmarkLandPrice.ConstructionUnit, //建设单位
- analysisArea: fxzmj, //分析面积(亩)
- ParticipationArea: jszmj, //参与地价计算的面积(亩)
- totalLandPrice: zdj, //总地价(万元) 总地价预估合计
- ghdkDetailedDjList: ghdkDetailedDjList, //规划地块详细地价
- picBase64List: [], //图片集 分析范围
- };
- },
- /**
- * 计算分析面积
- * @param {*} BenchmarkLandPrice 基准地价信息
- * @returns {number} 分析总面积
- */
- CalculateAnalysisArea(BenchmarkLandPrice) {
- let fxzmj = 0;
- let points = BenchmarkLandPrice.ProjectScope;
- let DataPs = points.map((item) => [item.x, item.y]);
- if (DataPs.length > 0) {
- if (
- JSON.stringify(DataPs[0]) != JSON.stringify(DataPs[DataPs.length - 1])
- ) {
- DataPs.push(DataPs[0]);
- }
- debugger;
- let polygonPs = polygon([DataPs]);
- let sdsd = area(polygonPs);
- let areaPs = area(polygonPs) * window.earthRadius;
- fxzmj = Number(areaPs / 666.66).toFixed(2);
- }
- return fxzmj;
- },
- /**
- * 计算两个面的交集面积
- * @param Points1
- * @param Points2
- * @param Points3
- */
- calculateIntersectArea(Points1, Points2, Points3) {
- var geometry1;
- var geometry2;
- var geometry3;
- if (Points1) {
- geometry1 = this.AssemblySurface(Points1);
- }
- if (Points2) {
- geometry2 = this.AssemblySurface(Points2);
- }
- if (Points3) {
- geometry3 = this.AssemblySurface(Points3);
- }
- let areaPs;
- if (geometry1 && geometry2) {
- areaPs = intersect(geometry1, geometry2);
- }
- if (areaPs && geometry3) {
- areaPs = intersect(areaPs, geometry3);
- }
- if (areaPs) {
- let areadifference = area(areaPs) * window.earthRadius;
- return Number(areadifference.toFixed(2));
- } else {
- return 0;
- }
- },
- /**
- * 组装带洞和不带洞的面
- * @param geometry 超图返回的图形数组
- */
- AssemblySurface(geometry) {
- let point3ds = [];
- let pointholes = [];
- let startindex = 0;
- for (let index = 0; index < geometry.parts.length; index++) {
- let thisps = [];
- let endindex = startindex + geometry.parts[index];
- let geometryPoints = geometry.points.slice(startindex, endindex);
- for (
- let pointindex = 0;
- pointindex < geometryPoints.length;
- pointindex++
- ) {
- let point = geometryPoints[pointindex];
- thisps.push([point.x, point.y]);
- }
- if (geometry.partTopo[index] === 1) {
- point3ds.push(thisps);
- } else {
- pointholes.push(thisps);
- }
- startindex = endindex;
- }
- // 主多边形
- var mainPolygon = polygon(point3ds);
- // 岛洞多边形
- var holePolygon = polygon(pointholes);
- // 计算差集 得到有导洞的图形
- var getdifference = difference(mainPolygon, holePolygon);
- return getdifference;
- },
- };
- /**
- * 基准地价分析
- */
- export default BenchmarkLandPrice;
|