JTS: 12 Descriptions 图形覆盖
这里写目录标题
- 版本
- 代码
- Intersection 交集
- Union 并集
- Difference 差集
- SymDifference 补集
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
/*** 图形覆盖操作* @author LiHan* 2023年10月12日 19:34:09*/
public class GeometryDescriptions {private final GeometryFactory geometryFactory = new GeometryFactory();private static final Logger LOGGER = LoggerFactory.getLogger(GeometryDescriptions.class);private static final WKTWriter WKT_WRITER = new WKTWriter();private final Coordinate[] coordinate1 = {new Coordinate(3, 9), new Coordinate(3, 4), new Coordinate(14, 4), new Coordinate(14, 9), new Coordinate(3, 9)};private final Coordinate[] coordinate2 = {new Coordinate(3, 6), new Coordinate(3, 1), new Coordinate(14, 1), new Coordinate(14, 6), new Coordinate(3, 6)};private final Polygon polygon1 = geometryFactory.createPolygon(coordinate1);private final Polygon polygon2 = geometryFactory.createPolygon(coordinate2);public static void main(String[] args) {GeometryDescriptions geometryDescriptions = new GeometryDescriptions();geometryDescriptions.test03();}
}
Intersection 交集
public void test00() {LOGGER.info("交集:{}", polygon1.intersection(polygon2));
}
Union 并集
public void test01() {LOGGER.info("并集:{}", polygon1.union(polygon2));
}
Difference 差集
public void test02() {Geometry geometry = polygon1.difference(polygon2);LOGGER.info("差集:{}", geometry);
}
SymDifference 补集
public void test03() {Geometry geometry = polygon1.symDifference(polygon2);LOGGER.info("补集:{}", geometry);
}