线段拼接算法

线段拼接算法

支持乱序,其他条件测试中。。。


var line1=[ [1578129.1099243, 5066588.4127197], [1578167.4275513, 5066174.4042969] ];
var line2=[ [1578167.4275513, 5066174.4042969], [1578190.6529541, 5065961.8389282] ];
var line3=[ [1578190.6529541, 5065961.8389282], [1578202.9593506, 5065854.7127075] ];
var line4=[ [1578202.9593506, 5065854.7127075], [1578209.6735229, 5065813.272522] ];
var line5=[ [1578336.1155396, 5065414.8660889], [1578216.2807007, 5065783.5911255], [1578209.6735229, 5065813.272522] ] ;

var linesArr = line1.concat(line2,line3,line4,line5);

var longLine = combineLines(linesArr);

  //线段拼接
  function combineLines(linesArr){
    var longLine=linesArr[0];
    let ptS = longLine[0];
    let ptE = longLine[longLine.length-1];
    let lineRet =[];
    let leftCount = 0;//剩下的点,如果匹配不上
    for (var i=1;i0){
        i=0;
        linesArr = lineRet;
        if (leftCount==lineRet.length) {
          return longLine;
        }
        leftCount = lineRet.length;
      }
    }
    return longLine;
  }

 

 

你可能感兴趣的:(GIS,javascript)