利用Turf.js实现点线面几何体的拓扑关系判断

通过官网http://turfjs.org/或者github https://github.com/Turfjs/turf了解

第一步:先引用js文件

<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>

第二步:调用函数,判断关系

booleanClockwise(line) //线是否闭合

var clockwiseRing = turf.lineString([[0,0],[1,1],[1,0],[0,0]]);
var counterClockwiseRing = turf.lineString([[0,0],[1,0],[1,1],[0,0]]);

turf.booleanClockwise(clockwiseRing)
//=true
turf.booleanClockwise(counterClockwiseRing)
//=false

booleanContains(feature1,feature2) //feature2是否完全包含在feature1中

var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
var point = turf.point([1, 2]);

turf.booleanContains(line, point);
//=true

booleanCrosses(feature1,feature2) //feature1,feature2是否相交

var line1 = turf.lineString([[-2, 2], [4, 2]]);
var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);

var cross = turf.booleanCrosses(line1, line2);
//=true

booleanDisjoint(feature1,feature2) //feature1,feature2是否相离

var point = turf.point([2, 2]);
var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);

turf.booleanDisjoint(line, point);
//=true

booleanEqual(feature1,feature2) //feature1,feature2是否重合

var pt1 = turf.point([0, 0]);
var pt2 = turf.point([0, 0]);
var pt3 = turf.point([1, 1]);

turf.booleanEqual(pt1, pt2);
//= true
turf.booleanEqual(pt2, pt3);
//= false

booleanOverlap(feature1,feature2) //feature1,feature2是否重叠 ,feature1,feature2类型为Polygon、LineString、 Multipoint、MultiLineString、MultiPolygon,且相同

var poly1 = turf.polygon([[[0,0],[0,5],[5,5],[5,0],[0,0]]]);
var poly2 = turf.polygon([[[1,1],[1,6],[6,6],[6,1],[1,1]]]);
var poly3 = turf.polygon([[[10,10],[10,15],[15,15],[15,10],[10,10]]]);

turf.booleanOverlap(poly1, poly2)
//=true
turf.booleanOverlap(poly2, poly3)
//=false

booleanParallel(line,line) //两条线是否平行

var line1 = turf.lineString([[0, 0], [0, 1]]);
var line2 = turf.lineString([[1, 0], [1, 1]]);

turf.booleanParallel(line1, line2);
//=true

booleanPointInPolygon(point,polygon) //点是否在面中

var pt = turf.point([-77, 44]);
var poly = turf.polygon([[
  [-81, 41],
  [-81, 47],
  [-72, 47],
  [-72, 41],
  [-81, 41]
]]);

turf.booleanPointInPolygon(pt, poly);
//= true

booleanPointOnLine(point,line) //点是否在线上

var pt = turf.point([0, 0]);
var line = turf.lineString([[-1, -1],[1, 1],[1.5, 2.2]]);
var isPointOnLine = turf.booleanPointOnLine(pt, line);
//=true

booleanWithin(feature1,feature2) //feature1是否完全在feature2中

var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
var point = turf.point([1, 2]);

turf.booleanWithin(point, line);
//=true

你可能感兴趣的:(GIS)