diff --git a/src/api/sys/layerManagement.ts b/src/api/sys/layerManagement.ts index 1748f85a..6ac114e1 100644 --- a/src/api/sys/layerManagement.ts +++ b/src/api/sys/layerManagement.ts @@ -1,5 +1,13 @@ import { defHttp } from '@/utils/http/axios'; -import { AddLayerParams,GetLayerListParams,AddGeomParams,GetGeomParams,LoginResultModel, GetUserInfoModel } from './model/layerModel'; +import { + AddLayerParams, + GetLayerListParams, + AddGeomParams, + GetGeomParams, + LoginResultModel, + GetUserInfoModel, + CalTubanAreaModel +} from './model/layerModel'; import { ErrorMessageMode } from '#/axios'; @@ -14,6 +22,8 @@ enum Api { GetLayerList = "/api/ShpLayerSource/LoadPage", AddGeom = "/api/ShpLayerSource/SaveShapeData", GetGeom = "/api/ShpLayerSource/GetShapeData", + CalTubanArea = "/api/DroneCaseInfoSingle/CalTubanArea", + SplitAndCalTubanArea = "/api/DroneCaseInfoSingle/SplitAndCalTubanArea", GetPermCode = '/getPermCode', TestRetry = '/testRetry', Login = '/api/Check/Login', @@ -106,6 +116,26 @@ export function getGeom(params:GetGeomParams) { ) } +export function calTubanArea(params:CalTubanAreaModel){ + return defHttp.post( + { + url: Api.CalTubanArea, + params, + } + ) +} + +export function splitAndCalTubanArea(params:CalTubanAreaModel){ + return defHttp.post( + { + url: Api.SplitAndCalTubanArea, + params, + } + ) +} + + + export function getConfig(params) { return defHttp.get( diff --git a/src/api/sys/model/layerModel.ts b/src/api/sys/model/layerModel.ts index 45206b11..e1411724 100644 --- a/src/api/sys/model/layerModel.ts +++ b/src/api/sys/model/layerModel.ts @@ -33,6 +33,19 @@ export interface GetGeomParams { limit:number, key:string | null, } + +export interface CalTubanAreaModel{ + wktgeom: string | null; + gengdi: number | null, + nongyongdi: number | null, + jibennongtian: number | null, + shengtaihongxian: number | null, + gengdituban:string, + nongyongdituban:string | null, + jibennongtiantuban:string | null, + shengtaihongxiantuban:string | null, + remaintuban:string | null +} export interface RoleInfo { roleName: string; diff --git a/src/components/MapboxMaps/MapComponent.vue b/src/components/MapboxMaps/MapComponent.vue index 531629a7..12d74bb1 100644 --- a/src/components/MapboxMaps/MapComponent.vue +++ b/src/components/MapboxMaps/MapComponent.vue @@ -107,7 +107,7 @@

导入图层分割

- +

地类图斑分割

@@ -323,6 +323,10 @@ import { message, Modal } from 'ant-design-vue'; import { useCloudQueryStore } from '@/store/modules/cloudquery'; + // 地类分割 + import { splitAndCalTubanArea } from '@/api/sys/layerManagement'; + import { CalTubanAreaModel } from '@/api/sys/model/layerModel'; + import { AddDroneTask, LoadLandType, AddDroneLandTask, LoadCloudQueryByCaseNo } from '@/api/demo/cloudQuery'; import { signal } from '@/utils/signalR'; // 坐标系转换 @@ -401,13 +405,200 @@ caseid:null, }) - // 选择地类类型 + // 地类分割图斑 const handlerSelectLandType = ()=>{ - splitPanelVisible.value = false; - LoadLandType().then(res=>{ - landTypeList.value = res; - }) - landTypeVisible.value = true; + + + emit('handlerStartSpliting',true); + + try{ + + let geom = GeojsonToWkt(JSON.parse(JSON.stringify(currentGeoJson.value.geometry))); + + let calAreaParams = { + "wktgeom":geom, + "type":"gengdi" + } + splitAndCalTubanArea(calAreaParams).then(res=>{ + if(res){ + let splitAfterFeatures = { + type: 'FeatureCollection', + features: [], + }; + + // 耕地 + if(res.gengdituban && !res.gengdituban.match("EMPTY")){ + let geometry = WktToGeojson(res.gengdituban) + // let geometry = WktToGeojson("POLYGON((118.20453045 34.61493194,118.2043834 34.61496477,118.20439868 34.61503472,118.20453843 34.61501303,118.20453045 34.61493194))"); + + let feature = { + "type": "Feature", + "properties": { + "id": generateUUID() + }, + "geometry": geometry + } + splitAfterFeatures.features.push(feature) + } + // 农用地 + if(res.nongyongdituban && !res.nongyongdituban.match("EMPTY")){ + let geometry = WktToGeojson(res.nongyongdituban) + // let geometry = WktToGeojson("POLYGON((118.20453902 34.61501903,118.20453045 34.61493194,118.20453843 34.61501303,118.20439868 34.61503472,118.2043834 34.61496477,118.20441053 34.61508898,118.20387087 34.61518892,118.20387087 34.61526887,118.20442195 34.61517464,118.20442195 34.61515465,118.2048474 34.61509184,118.20482741 34.61498048,118.20453902 34.61501903))") + let feature = { + "type": "Feature", + "properties": { + "id": generateUUID() + }, + "geometry": geometry + } + splitAfterFeatures.features.push(feature) + } + // 基本农田 + if(res.jibennongtiantuban && !res.jibennongtiantuban.match("EMPTY")){ + let geometry = WktToGeojson(res.jibennongtiantuban) + let feature = { + "type": "Feature", + "properties": { + "id": generateUUID() + }, + "geometry": geometry + } + splitAfterFeatures.features.push(feature) + } + // + if(res.remaintuban && !res.remaintuban.match("EMPTY")){ + let geometry = WktToGeojson(res.remaintuban) + let feature = { + "type": "Feature", + "properties": { + "id": generateUUID() + }, + "geometry": geometry + } + splitAfterFeatures.features.push(feature) + } + // 生态保护红线 + if(res.shengtaihongxiantuban && !res.shengtaihongxiantuban.match("EMPTY")){ + let geometry = WktToGeojson(res.shengtaihongxiantuban) + let feature = { + "type": "Feature", + "properties": { + "id": generateUUID() + }, + "geometry": geometry + } + splitAfterFeatures.features.push(feature) + } + + console.log("splitAfterFeatures",splitAfterFeatures); + // 分割数据返回父组件中 + emit('handlerSplitPolygon', splitAfterFeatures.features); + handlerUnDraw(); + } + }).catch((e)=>{ + emit('handlerStartSpliting',false); + }) + + }catch(e){ + + emit('handlerStartSpliting',false); + + } + + // let res = { + // "wktgeom": null, + // "gengdi": 0.17, + // "nongyongdi": 1.64, + // "jibennongtian": 0, + // "shengtaihongxian": 0, + // "gengdituban": "POLYGON((118.204530452946 34.6149319373947,118.204383402255 34.6149647739564,118.20439867709747 34.6150347166548,118.2045384290743 34.61501302803828,118.204530452946 34.6149319373947))", + // "nongyongdituban": "POLYGON((118.204827409679 34.6149804783991,118.204539019005 34.6150190256674,118.204530452946 34.6149319373947,118.204383402255 34.6149647739564,118.204410528111 34.615088981821,118.203870866355 34.6151889191832,118.203870866355 34.6152688690729,118.204421949524 34.6151746424171,118.204421949524 34.6151546549447,118.204847397152 34.6150918371741,118.204827409679 34.6149804783991))", + // "jibennongtiantuban": "", + // "shengtaihongxiantuban": "", + // "remaintuban": "POLYGON EMPTY" + // } + + // if(res){ + // let splitAfterFeatures = { + // type: 'FeatureCollection', + // features: [], + // }; + + // // 耕地 + // if(res.gengdituban && !res.gengdituban.match("EMPTY")){ + // let geometry = WktToGeojson(res.gengdituban) + + // let feature = { + // "type": "Feature", + // "properties": { + // "id": generateUUID() + // }, + // "geometry": geometry + // } + // splitAfterFeatures.features.push(feature) + // } + // // 农用地 + // if(res.nongyongdituban && !res.nongyongdituban.match("EMPTY")){ + // let geometry = WktToGeojson(res.nongyongdituban) + // let feature = { + // "type": "Feature", + // "properties": { + // "id": generateUUID() + // }, + // "geometry": geometry + // } + // splitAfterFeatures.features.push(feature) + // } + // // 基本农田 + // if(res.jibennongtiantuban && !res.jibennongtiantuban.match("EMPTY")){ + // let geometry = WktToGeojson(res.jibennongtiantuban) + // let feature = { + // "type": "Feature", + // "properties": { + // "id": generateUUID() + // }, + // "geometry": geometry + // } + // splitAfterFeatures.features.push(feature) + // } + // // + // if(res.remaintuban && !res.remaintuban.match("EMPTY")){ + // let geometry = WktToGeojson(res.remaintuban) + // let feature = { + // "type": "Feature", + // "properties": { + // "id": generateUUID() + // }, + // "geometry": geometry + // } + // splitAfterFeatures.features.push(feature) + // } + // // 生态保护红线 + // if(res.shengtaihongxiantuban && !res.shengtaihongxiantuban.match("EMPTY")){ + // let geometry = WktToGeojson(res.shengtaihongxiantuban) + // let feature = { + // "type": "Feature", + // "properties": { + // "id": generateUUID() + // }, + // "geometry": geometry + // } + // splitAfterFeatures.features.push(feature) + // } + + // // 分割数据返回父组件中 + // emit('handlerSplitPolygon', splitAfterFeatures.features); + // handlerUnDraw(); + // } + // splitAndCalTubanArea(calAreaParams).then(res=>{ + + // }) + + // splitPanelVisible.value = false; + // LoadLandType().then(res=>{ + // landTypeList.value = res; + // }) + // landTypeVisible.value = true; } // 使用地类分割 @@ -589,6 +780,7 @@ 'handlerDrawComplete', 'handlerGetFormDetail', 'handlerSplitPolygon', + 'handlerStartSpliting', 'onFeatureClick', ]); @@ -967,7 +1159,7 @@ splitPolygon.geometry.coordinates[0][index] = [item[0],item[1]]; }) - //console.log("editGeoJson",editGeoJson.value); + console.log("splitLineString",splitLineString); let features = splitPolygonByLine(splitLineString, JSON.parse(JSON.stringify(editGeoJson.value))); if(features){ @@ -979,6 +1171,7 @@ splitAfterFeatures.features = tempFeatures; + console.log("tempFeatures",tempFeatures); // 分割数据返回父组件中 emit('handlerSplitPolygon', tempFeatures); @@ -1370,6 +1563,7 @@ }; const handlerCancleDraw = () => { + if (drawTool) { map.removeControl(drawTool); drawTool = null; diff --git a/src/components/MapboxMaps/lib/splitpolygon.ts b/src/components/MapboxMaps/lib/splitpolygon.ts index 4d6c780d..5d988997 100644 --- a/src/components/MapboxMaps/lib/splitpolygon.ts +++ b/src/components/MapboxMaps/lib/splitpolygon.ts @@ -41,6 +41,7 @@ export function splitPolygonByLine(line, outerPolygon) { }else if(outerPolygon.geometry.type == "Polygon"){ // 如果是Polygon的单图斑 直接获取分割结果 let splitRes = splitByLine(line,outerPolygon); + // 如果有数据就拼接数据 if(splitRes){ splitAfterFeatures = splitAfterFeatures.concat(splitRes); @@ -49,7 +50,6 @@ export function splitPolygonByLine(line, outerPolygon) { splitAfterFeatures = splitAfterFeatures.concat(outerPolygon); } } - //console.log("splitAfterFeatures",splitAfterFeatures) return splitAfterFeatures; @@ -163,7 +163,7 @@ function splitByLine(line,outerPolygon){ //console.log("第1步:传入的分割线数据",line); - //console.log("第2步:传入的分割面数据",outerPolygon) + // console.log("第2步:传入的分割面数据",outerPolygon) // 处理被分割的面数据坐标小数点保留多少位 @@ -180,7 +180,7 @@ function splitByLine(line,outerPolygon){ //将点合并成MultiPoint let intersectCombined = turf.combine(intersectCollection).features[0]; - //console.log("第5步:分割后所有点数据",intersectCombined) + console.log("第5步:分割后所有点数据",intersectCombined) //分别获取切割线 @@ -195,11 +195,11 @@ function splitByLine(line,outerPolygon){ let pieceCollection = turf.featureCollection( outerPieceCollection.features.concat(splitterPieceCollection.features), ); - //console.log("第8步:所有分割线段",pieceCollection); + console.log("第8步:所有分割线段",pieceCollection); //使用turf将闭合线组成多边形 let polygonCollection = turf.polygonize(pieceCollection); - //console.log("第9步:分割线合并面数据",polygonCollection) + // console.log("第9步:分割线合并面数据",polygonCollection) //对多边形进行判断,切割外的多边形丢弃 let innerPolygons = polygonCollection.features.filter((polygon) => { diff --git a/src/components/MapboxMaps/src/WktGeojsonTransform.ts b/src/components/MapboxMaps/src/WktGeojsonTransform.ts index 10a689ed..c62a0620 100644 --- a/src/components/MapboxMaps/src/WktGeojsonTransform.ts +++ b/src/components/MapboxMaps/src/WktGeojsonTransform.ts @@ -15,4 +15,33 @@ const GeojsonToWkt = (geojsonData)=> { } -export {WktToGeojson,GeojsonToWkt} \ No newline at end of file +const removeZM = (geoJSON) => { + + function removeZMFromCoords(coords) { + return coords.map((coord) => [coord[0], coord[1]]); // 只保留 X 和 Y + } + + switch (geoJSON.type) { + case 'Point': + geoJSON.coordinates = removeZMFromCoords([geoJSON.coordinates]).flat(); + break; + case 'LineString': + case 'MultiPoint': + geoJSON.coordinates = removeZMFromCoords(geoJSON.coordinates); + break; + case 'Polygon': + case 'MultiLineString': + geoJSON.coordinates = geoJSON.coordinates.map((ring) => removeZMFromCoords(ring)); + break; + case 'MultiPolygon': + geoJSON.coordinates = geoJSON.coordinates.map((polygon) => + polygon.map((ring) => removeZMFromCoords(ring)) + ); + break; + default: + throw new Error(`Unsupported geometry type: ${geoJSON.type}`); + } + return geoJSON; + } + +export {WktToGeojson,GeojsonToWkt,removeZM} \ No newline at end of file diff --git a/src/views/demo/degraining/curbspotcity/MapList/SplitPolygonModal/index.vue b/src/views/demo/degraining/curbspotcity/MapList/SplitPolygonModal/index.vue index 02f5143c..48f78b51 100644 --- a/src/views/demo/degraining/curbspotcity/MapList/SplitPolygonModal/index.vue +++ b/src/views/demo/degraining/curbspotcity/MapList/SplitPolygonModal/index.vue @@ -1,5 +1,10 @@