这里写目录标题
- 版本
- 点与线
- 点与面
- 线与面
- 线与线
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
public class GeometryCrosses {
private final GeometryFactory geometryFactory = new GeometryFactory();
private static final Logger LOGGER = LoggerFactory.getLogger(GeometryCrosses.class);
private static final WKTWriter WKT_WRITER = new WKTWriter();
private Coordinate[] coordinate1;
private Coordinate[] coordinate2;
/**
* [T*T******] (for P/L, P/A, and L/A situations) 点与线,点与面,线与面
* [T*****T**] (for L/P, A/P, and A/L situations) 线与点,面与点,面与线
* [0********] (for L/L situations) 线与线
* 获取两个几何对象并返回 true 如果它们的交叉点在空间上是交叉的,
* 也就是说,几何图形有一些但不是所有的内部点是共同的。
* 几何图形内部的交点不能是空集,并且其维度必须小于两个输入几何图形的最大尺寸。
* 此外,两个几何图形的交点不能等于任何一个源几何图形。否则,它将返回 false
*/
public static void main(String[] args) {
GeometryCrosses geometryCrosses = new GeometryCrosses();
geometryCrosses.test00();
}
}
点与线
/**
* 点与线, 点必须是多点,且有一个点在线上,因为是交叉点,在线上
* [T*T******]
*/
public void test00() {
coordinate1 = new Coordinate[] {
new Coordinate(4, 3), new Coordinate(13, 3)
};
LineString lineString = geometryFactory.createLineString(coordinate1);
coordinate2 = new Coordinate[] {
new Coordinate(8, 6), new Coordinate(8, 1), new Coordinate(9, 3)
};
MultiPoint multiPoint = geometryFactory.createMultiPointFromCoords(coordinate2);
LOGGER.info("lineString1 - point1 九交模型值:{}", lineString.relate(multiPoint).toString());
LOGGER.info("point1 - lineString1 跨越:{}", lineString.crosses(multiPoint));
LOGGER.info("lineString1: {}, point1: {}", WKT_WRITER.write(lineString), WKT_WRITER.write(multiPoint));
}
点与面
/**
* 点与面
* [T*T******]
*/
public void test01() {
coordinate1 = new Coordinate[] {
new Coordinate(8, 6), new Coordinate(8, 1), new Coordinate(9, 3)
};
MultiPoint multiPoint = geometryFactory.createMultiPointFromCoords(coordinate1);
coordinate2 = new Coordinate[] {
new Coordinate(2, 5), new Coordinate(2, 2), new Coordinate(12, 2), new Coordinate(12, 5), new Coordinate(2, 5)
};
Polygon polygon = geometryFactory.createPolygon(coordinate2);
LOGGER.info("multiPoint1 - polygon 九交模型值:{}", multiPoint.relate(polygon).toString());
LOGGER.info("multiPoint1 - polygon 跨越:{}", multiPoint.crosses(polygon));
LOGGER.info("multiPoint1: {}, polygon: {}", WKT_WRITER.write(multiPoint), WKT_WRITER.write(polygon));
}
线与面
public void test02() {
coordinate1 = new Coordinate[] {
new Coordinate(8, 6), new Coordinate(8, 1), new Coordinate(9, 3)
};
LineString lineString = geometryFactory.createLineString(coordinate1);
coordinate2 = new Coordinate[] {
new Coordinate(2, 5), new Coordinate(2, 2), new Coordinate(12, 2), new Coordinate(12, 5), new Coordinate(2, 5)
};
Polygon polygon = geometryFactory.createPolygon(coordinate2);
LOGGER.info("lineString - polygon 九交模型值:{}", lineString.relate(polygon).toString());
LOGGER.info("lineString - polygon 跨越:{}", lineString.crosses(polygon));
LOGGER.info("lineString: {}, polygon: {}", WKT_WRITER.write(lineString), WKT_WRITER.write(polygon));
}
线与线
/**
* 线与线
* [0********]
*/
public void test03() {
coordinate1 = new Coordinate[] {
new Coordinate(3, 4), new Coordinate(12, 4)
};
LineString lineString1 = geometryFactory.createLineString(coordinate1);
coordinate2 = new Coordinate[] {
new Coordinate(7, 7), new Coordinate(7, 1)
};
LineString lineString2 = geometryFactory.createLineString(coordinate2);
LOGGER.info("lineString - polygon 九交模型值:{}", lineString1.relate(lineString2).toString());
LOGGER.info("lineString - polygon 跨越:{}", lineString1.crosses(lineString2));
LOGGER.info("lineString: {}, polygon: {}", WKT_WRITER.write(lineString1), WKT_WRITER.write(lineString2));
}