【问题标题】:Intersect between Polygon and Multipolygon using turfjs使用 turfjs 在 Polygon 和 Multipolygon 之间相交
【发布时间】:2016-08-01 03:01:28
【问题描述】:

我使用 turfjs 执行 turfjs 的相交函数时出错

绘制的图层是“Polygon”,而我希望它与“MultiPolygon”图层相交。

这是我的代码的 sn-p:

$.getJSON("FloodHazard_CRB_100Year.json", function(baha) { 
            //addDataToMap(data, map); 
            console.log(json);
            console.log(baha);
            //check_intersect(baha,json);
            f1 = baha.features;
            f2 = json.features;

            var conflictlist;

            for (var i = 0; i < f1.length; i++) {
                var parcel1 = f1[i];
                for (var j = 0; j <f2.length; j++) {
                    var parcel2 = f2[j];
                    //console.log("Processing",i,j);
                        var conflict = turf.intersect(parcel1, parcel2);
                        if (conflict != null) {
                            conflictlist = conflict;
                        }
                }
            }
            var intersect_style = {
                fillColor: "#ff0000",
                color: "#000",
                opacity: 1,
                weight:0.5,
                fillOpacity: 0.8
            };
            L.geoJson(conflictlist,{
                style: intersect_style
            }).addTo(map);
            console.log(conflictlist);

            //check_intersect(json);
        });

【问题讨论】:

    标签: javascript leaflet turfjs


    【解决方案1】:

    首先请注意,Turf 需要完整的 GeoJSON Feature 对象作为参数,而不仅仅是它们的 geometry

    如果我的理解是正确的,那么您的第二个循环是一种解决方法,只需要将多边形传递给turf.intersect,而不是多多边形?

    在这种情况下,您首先需要将 MutiPolygon 正确转换为具有多边形几何形状的要素集合或数组。然后你可以循环它们来执行你的交集。

    【讨论】:

    • 草皮是否允许多边形和多多边形之间相交?
    • 不知道,试试看吧! :-)
    • 我试过了,不行。我认为它不能迭代MultiPolygon。啧啧
    • 如何将 MultiPolygon 转换为 Polygons?
    猜你喜欢
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 2020-10-06
    • 2023-01-19
    相关资源
    最近更新 更多