简体   繁体   English

根据二维数组中的坐标在地图上绘制多边形

[英]Drawing a polygon in map based on coordinates from a two dimensional array

Given a two-dimensional array looking like this (I'm drawing it up as a grid): 给定一个看起来像这样的二维数组(我将其绘制为网格):
[0][0][0] [1][1] [0][0] [1][1] [0] [0] [0] [0] [1] [1] [0] [0] [1] [1] [0]
[0] [1][1] [1] [1] [0] [1] [1] [1] [0] [0] [1] [1] [1] [1] [0] [1] [1] [1] [0]
[0] [1] [1][1] [1] [0][0] [1][1] [0] [0] [1] [1] [1] [1] [0] [0] [1] [1] [0]
[0] [1][1] [1] [1] [0][0][0][0][0] [0] [1] [1] [1] [1] [0] [0] [0] [0] [0]
[0][0][0] [1][1] [0][0][0][0][0] [0] [0] [0] [1] [1] [0] [0] [0] [0] [0]

I want to extract the 1's that are bold, and ignore those that are italic. 我想提取粗体的1,而忽略斜体的1。 My 1's represent gps coordinates that I want to use as input to a MultiPolygon feature in a GeoJSON document. 我的1代表我要用作GeoJSON文档中MultiPolygon功能输入的gps坐标。

Right now I iterate through each row and create MultiLineString, but that is really not what I want. 现在,我遍历每一行并创建MultiLineString,但这确实不是我想要的。

var previousValue = -1;
var line = [];
var lines = [];
var points = [];
for (var i = 0; i < data.length; i++) {
    var value = data[i];

    if (value == 0 || (previousValue > -1 && value != previousValue)) {
        // Line interrupted, push it to features and create a new
        if (line.length === 1) { // It's not a line, but a point
            //this.common.log.info("Push point");
            points.push(line);
        } else if (line.length === 2 && previousValue > -1) {
            lines.push(line);
        }
        line = [];
    }
    if (value > 0) {
        if (line.length == 0) {
            // Start of line
            line.push(value);
        } else if (line.length == 1) {
            // Line has only a starting point, add to end
            line.push(value);
        } else {
            // Line has already an endpoint, update it
            line[1] = value;
        }
    }
    previousValue = value;
}

I guess there is a library for this? 我想这里有图书馆吗?

You can try a marching squares algorithm (like in the comment) but I recommend an alpha shapes. 您可以尝试使用行进平方算法(如注释中所示),但我建议使用alpha形状。 Its a delaunay triangulation without edges exceeding alpha. 它是delaunay三角剖分,且边线不超过alpha。 The marching cube isn't the right for concave hull. 行进的立方体不适用于凹面船体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM