如何利用jts将点云构造成一个多边形

背景

现有许多离散点,需要将其构造成一个外包多边


原理

利用JTS提供的Tin算法能力

 

实现:

Coordinate[] coordinates = new Coordinate[]{
				new Coordinate(0, 1),
				new Coordinate(3, 4),
				new Coordinate(1, 0),
				new Coordinate(2, 0),
				new Coordinate(2, 3),
				new Coordinate(1, 2),
				new Coordinate(3, 1),
				new Coordinate(1, 1),
				new Coordinate(2, 2)};
		
		/*Coordinate[] coordinates = new Coordinate[]{
				new Coordinate(0, 0),
				new Coordinate(1, 1),
				new Coordinate(2, 3)};*/
		GeometryFactory gf = new GeometryFactory();
		MultiPoint mp = gf.createMultiPoint(coordinates);
		ConformingDelaunayTriangulationBuilder builder = new ConformingDelaunayTriangulationBuilder();
	
		builder.setSites(mp);
		//实际为GeometryCollection(组成的geometry紧密相连)
		Geometry ts = builder.getTriangles(gf);
		
		//以0的距离进行缓冲(因为各多边形两两共边),生成一个多边形
		//此时则将点云构造成了多边形
		Geometry union = ts.buffer(0);
		String text = union.toText();
		System.out.println(text);





你可能感兴趣的:(Gis,多边形,点云)