python 泰森多边形边界_geotools中泰森多边形的生成
时间: 2024-01-03 13:04:25 浏览: 148
在geotools中,可以使用TriangulationBuilder类来生成泰森多边形边界。具体步骤如下:
1. 创建Point集合
```python
List<Point> points = new ArrayList<>();
```
2. 将要生成泰森多边形的点添加到Point集合中
```python
points.add(new GeometryFactory().createPoint(new Coordinate(0, 0)));
points.add(new GeometryFactory().createPoint(new Coordinate(10, 0)));
points.add(new GeometryFactory().createPoint(new Coordinate(10, 10)));
points.add(new GeometryFactory().createPoint(new Coordinate(0, 10)));
```
3. 创建TriangulationBuilder对象并设置点集合
```python
TriangulationBuilder tb = new TriangulationBuilder();
tb.setSites(points);
```
4. 生成Delaunay三角网
```python
Geometry triangulation = tb.getTriangles(new GeometryFactory());
```
5. 生成泰森多边形边界
```python
Geometry boundary = triangulation.convexHull();
```
完整示例代码如下:
```python
import java.util.ArrayList;
import java.util.List;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.triangulate.ConformingDelaunayTriangulationBuilder;
import org.locationtech.jts.triangulate.TriangulationBuilder;
public class Main {
public static void main(String[] args) {
List<Point> points = new ArrayList<>();
points.add(new GeometryFactory().createPoint(new Coordinate(0, 0)));
points.add(new GeometryFactory().createPoint(new Coordinate(10, 0)));
points.add(new GeometryFactory().createPoint(new Coordinate(10, 10)));
points.add(new GeometryFactory().createPoint(new Coordinate(0, 10)));
TriangulationBuilder tb = new ConformingDelaunayTriangulationBuilder();
tb.setSites(points);
Geometry triangulation = tb.getTriangles(new GeometryFactory());
Geometry boundary = triangulation.convexHull();
System.out.println(boundary);
}
}
```
阅读全文