|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import { reject } from 'lodash-es';
|
|
|
|
|
import { generateUUID } from '../src/tool';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -77,7 +78,8 @@ export function splitPolygonByLine(line, outerPolygon) {
|
|
|
|
|
innerPolygons = innerPolygons.map((polygon) => {
|
|
|
|
|
let diff = polygon;
|
|
|
|
|
turf.featureEach(holeCollection, (hole) => {
|
|
|
|
|
diff = turf.difference(diff, hole);
|
|
|
|
|
// diff = turf.difference(diff, hole);
|
|
|
|
|
diff = turf.difference(turf.featureCollection([diff, hole]))
|
|
|
|
|
});
|
|
|
|
|
return diff;
|
|
|
|
|
});
|
|
|
|
|
@ -91,6 +93,7 @@ export function splitPolygonByLine(line, outerPolygon) {
|
|
|
|
|
return innerPolygons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取多边形内随机点
|
|
|
|
|
function getRandomPointInPolygon(polygon) {
|
|
|
|
|
const bbox = turf.bbox(polygon); // 获取多边形的边界框
|
|
|
|
|
let point;
|
|
|
|
|
@ -103,27 +106,81 @@ function getRandomPointInPolygon(polygon) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 单个面数据分割
|
|
|
|
|
export function splitPolygonByFill(drawPolygon, outerPolygon) {
|
|
|
|
|
|
|
|
|
|
console.log("drawPolygon",drawPolygon);
|
|
|
|
|
console.log("outerPolygon",outerPolygon)
|
|
|
|
|
|
|
|
|
|
var polygon1 = turf.polygon(drawPolygon.geometry.coordinates)
|
|
|
|
|
var polygon2 = turf.polygon(outerPolygon.geometry.coordinates);
|
|
|
|
|
var difference = turf.difference(polygon2,polygon1);
|
|
|
|
|
var intersection = turf.intersect(polygon2, polygon1);
|
|
|
|
|
|
|
|
|
|
intersection.properties.id = generateUUID();
|
|
|
|
|
difference.properties.id = generateUUID();
|
|
|
|
|
|
|
|
|
|
let splitAfterFeatures = [intersection,difference];
|
|
|
|
|
|
|
|
|
|
// splitAfterFeatures?.forEach((item,index)=>{
|
|
|
|
|
// splitAfterFeatures[index].properties?.id = generateUUID();
|
|
|
|
|
// })
|
|
|
|
|
export async function splitPolygonByFill(drawPolygon, outerPolygon) {
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
try{
|
|
|
|
|
console.log("第1步:传入的绘制面数据",drawPolygon);
|
|
|
|
|
console.log("第2步:传入的被切割面数据",outerPolygon)
|
|
|
|
|
|
|
|
|
|
var polygon1 = turf.polygon(drawPolygon.geometry.coordinates);
|
|
|
|
|
var polygon2 = turf.polygon(outerPolygon.geometry.coordinates);
|
|
|
|
|
|
|
|
|
|
// var intersection = turf.intersect(polygon1, polygon2);
|
|
|
|
|
let intersection = turf.intersect(turf.featureCollection([polygon1, polygon2]));
|
|
|
|
|
console.log("第4步:获取绘制图斑和分割图斑的交集",JSON.stringify(polygon2),JSON.stringify(polygon1),intersection);
|
|
|
|
|
|
|
|
|
|
var difference = turf.difference(turf.featureCollection([polygon2, polygon1]));
|
|
|
|
|
console.log("第3步:获取绘制图斑和分割图斑的差集",difference);
|
|
|
|
|
|
|
|
|
|
let splitAfterFeatures = [intersection,difference];
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
console.log("splitAfterFeatures9876",splitAfterFeatures);
|
|
|
|
|
},3000)
|
|
|
|
|
resolve(splitAfterFeatures)
|
|
|
|
|
}catch(e){
|
|
|
|
|
console.log(e);
|
|
|
|
|
reject(null);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return splitAfterFeatures;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 多面数据分割裁剪
|
|
|
|
|
export async function splitPolygonByMultiFill(drawPolygons,outerPolygon){
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
try{
|
|
|
|
|
console.log("drawPolygons",drawPolygons,outerPolygon);
|
|
|
|
|
// 所有结果集合
|
|
|
|
|
let resultArray = [];
|
|
|
|
|
|
|
|
|
|
// 绘制图斑和分割图斑集合数组
|
|
|
|
|
let featuresArray = [];
|
|
|
|
|
featuresArray.push(turf.polygon(outerPolygon.geometry.coordinates));
|
|
|
|
|
|
|
|
|
|
// 绘制图斑数组
|
|
|
|
|
let splitFeaturesArray = [];
|
|
|
|
|
|
|
|
|
|
// 求交集图斑
|
|
|
|
|
drawPolygons.forEach((item,index)=>{
|
|
|
|
|
let turfPolygon = turf.polygon(item.geometry.coordinates);
|
|
|
|
|
|
|
|
|
|
// 取交集
|
|
|
|
|
let intersection = turf.intersect(turf.featureCollection([featuresArray[0],turfPolygon]));
|
|
|
|
|
if(intersection){
|
|
|
|
|
resultArray.push(intersection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("交集"+index+":",intersection)
|
|
|
|
|
splitFeaturesArray.push(turfPolygon);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 取差集
|
|
|
|
|
var difference = turf.difference(turf.featureCollection(featuresArray.concat(splitFeaturesArray)));
|
|
|
|
|
if(difference){
|
|
|
|
|
resultArray.push(difference);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 全部图斑
|
|
|
|
|
console.log("resultArray",resultArray);
|
|
|
|
|
|
|
|
|
|
resolve(resultArray)
|
|
|
|
|
|
|
|
|
|
}catch(e){
|
|
|
|
|
reject("分割失败!");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function printLngLat(arr){
|
|
|
|
|
|