From 01f256af0432079b265d2dfe9bda6f892f269b66 Mon Sep 17 00:00:00 2001
From: helloxujingliang <3225043@qq.com>
Date: Wed, 9 Oct 2024 15:28:31 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=9B=BE=E6=96=91=E5=88=86?=
=?UTF-8?q?=E5=89=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/MapboxMaps/lib/splitpolygon.ts | 47 ++++++++++++++++---
.../Upload/src/components/FilePreview.vue | 12 +++++
2 files changed, 53 insertions(+), 6 deletions(-)
create mode 100644 src/components/Upload/src/components/FilePreview.vue
diff --git a/src/components/MapboxMaps/lib/splitpolygon.ts b/src/components/MapboxMaps/lib/splitpolygon.ts
index 1aabe00a..c82aec57 100644
--- a/src/components/MapboxMaps/lib/splitpolygon.ts
+++ b/src/components/MapboxMaps/lib/splitpolygon.ts
@@ -147,6 +147,8 @@ export async function splitPolygonByFill(drawPolygon, outerPolygon) {
// 多面数据分割裁剪
export async function splitPolygonByMultiFill(drawPolygons,outerPolygon){
+ let tempDrawPolygons = [...drawPolygons]
+ drawPolygons = handlerMultiPolygonToPolygon(tempDrawPolygons);
return new Promise((resolve,reject)=>{
try{
@@ -170,14 +172,24 @@ export async function splitPolygonByMultiFill(drawPolygons,outerPolygon){
console.log("原始数据处理精度后坐标",featuresArray);
// 求交集图斑
drawPolygons.forEach((item,index)=>{
- let turfPolygon = turf.truncate(turf.polygon(item.geometry.coordinates),dealOptions);
+
+
+
+ //
+ console.log("coordinates",index,item.geometry.coordinates)
+ try{
+ let turfPolygon = turf.truncate(turf.polygon(item.geometry.coordinates),dealOptions);
// 取交集
- let intersection = turf.intersect(turf.featureCollection([featuresArray[0],turfPolygon]));
- if(intersection){
- resultArray.push(intersection);
+ let intersection = turf.intersect(turf.featureCollection([featuresArray[0],turfPolygon]));
+ if(intersection){
+ resultArray.push(intersection);
+ }
+ console.log("第3步:交集"+index+":",intersection)
+ splitFeaturesArray.push(turfPolygon);
+ }catch(e){
+ console.log(e);
}
- console.log("第3步:交集"+index+":",intersection)
- splitFeaturesArray.push(turfPolygon);
+
})
// 取差集
@@ -201,6 +213,29 @@ export async function splitPolygonByMultiFill(drawPolygons,outerPolygon){
})
}
+// MultiPolygon转换Polygon
+export function handlerMultiPolygonToPolygon(sourcePolygons){
+ let polygons = [];
+ sourcePolygons.forEach((item,ndex)=>{
+ if(item.geometry.type == "MultiPolygon"){
+ item.geometry.coordinates.forEach((coorItem,idx)=>{
+ let polygonItem = {
+ "type": "Feature",
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": coorItem
+ },
+ "properties": {}
+ }
+ polygons.push(polygonItem);
+ })
+ }else if(item.geometry.type == "Polygon"){
+ polygons.push(item);
+ }
+ })
+ return polygons;
+}
+
export function printLngLat(arr){
arr.forEach((item,index)=>{
console.log(item[1]+","+item[0]+"\n");
diff --git a/src/components/Upload/src/components/FilePreview.vue b/src/components/Upload/src/components/FilePreview.vue
new file mode 100644
index 00000000..5cf4a09f
--- /dev/null
+++ b/src/components/Upload/src/components/FilePreview.vue
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
\ No newline at end of file