1

我正在尝试使用turfjs中的pointsWithinPolygon在多个多边形内获取一些点,但结果出乎意料。

pointsWithinPolygon是否有可能与FeatureCollection不兼容?

这是我的用法示例。

let points = {
    "type": "Point",
    "coordinates": [
        106.866995, -6.261513
    ]
}

let filter = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "IdArea": 4
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            106.314674,
                            -6.6348689124
                        ],
                        [
                            107.5781628906,
                            -6.6348689124
                        ],
                        [
                            107.5781628906,
                            -5.9742195859
                        ],
                        [
                            106.314674,
                            -5.9742195859
                        ],
                        [
                            106.314674,
                            -6.6348689124
                        ]
                    ]
                ]
            }
        }
    ]
}

let result = turf.pointsWithinPolygon(points, filter);
console.log(result); 
4

1 回答 1

1

您正在尝试使用 geoJsons 作为草皮的 pointsWithinPolygons 函数的输入。

该函数采用 turf.points 点数组和 turf.polygon 多边形顶点数组。

根据您建立的变量,您需要调用:

let result = turf.pointsWithinPolygon(turf.points([points.coordinates]), turf.polygon(filter.features.geometry.coordinates));
于 2018-11-11T07:38:27.450 回答