将 turfjs turf.lineChunk 的输出转换为 turf.points

问题描述 投票:0回答:1

只是想知道是否有一种方法可以轻松地将 turf.lineChunk 的输出转换为 turf.points?

     testLineString = {
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "LineString",
            "coordinates": [                    
                [
                    155.9668,
                    -2.9402
                ],
                [
                    162.959225,
                    -2.94504
                ],
            ]
        }                   
    };

var chunk = turf.lineChunk(testLineString, 25, { units: "kilometers" });

var points = turf.points([ [], [], [], ]);

希望有这样简单的事情(但这行不通)

var points = turf.points(chunk.features); 

我希望这些点能够在 turf.pointsWithinPolygon() 中使用

var inside = turf.pointsWithinPolygon(points ,turfpolygon);

谢谢你。

turfjs
1个回答
0
投票

除了像下面这样的循环之外,似乎不是一个简单的方法:

for (var x = 0; x < chunkedLine.features.length; x++) {
  if (foundWithinPolygon == false) {
                                    points = turf.points([
                                        [chunkedLine.features[x].geometry.coordinates[0][0], chunkedLine.features[x].geometry.coordinates[0][1]],
                                        [chunkedLine.features[x].geometry.coordinates[1][0], chunkedLine.features[x].geometry.coordinates[1][1]],
                                    ]);
                                    var ptsWithin = turf.pointsWithinPolygon(points, turfpolygon);
                                    if (ptsWithin.features.length > 0) {
                                        foundWithinPolygon = true;
                                        break;
                                    }
                    }
    }
© www.soinside.com 2019 - 2024. All rights reserved.