文章目录
- 版本
- 代码
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
package pers.stu.algorithm;
import org.locationtech.jts.algorithm.locate.IndexedPointInAreaLocator;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateArrays;
import org.locationtech.jts.geom.GeometryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 判断是否在点在面的内部
* @author LiHan
* 2023-11-10 10:11:30
*/
public class IndexedPointInAreaLocatorUse {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexedPointInAreaLocatorUse.class);
private final GeometryFactory geometryFactory = new GeometryFactory();
public static void main(String[] args) {
IndexedPointInAreaLocatorUse indexedPointInAreaLocatorUse = new IndexedPointInAreaLocatorUse();
indexedPointInAreaLocatorUse.test00();
}
public void test00() {
Coordinate[] coordinates1 = new Coordinate[] {
new Coordinate(3, 8),new Coordinate(10, 8),new Coordinate(10, 3),new Coordinate(3, 3),
new Coordinate(3, 8)
};
Coordinate[] coordinates2 = new Coordinate[] {
new Coordinate(6, 5), new Coordinate(10,6), new Coordinate(13,5)
};
IndexedPointInAreaLocator indexedPointInAreaLocator = new IndexedPointInAreaLocator(geometryFactory.createPolygon(coordinates1));
for (Coordinate coordinate : coordinates2) {
// org.locationtech.jts.geom.Location
// 0 内部,1 边界,2 外部
LOGGER.info("是否在面里:{}", indexedPointInAreaLocator.locate(coordinate));
}
}
}
18:12:43.842 [main] INFO pers.stu.algorithm.IndexedPointInAreaLocatorUse - 是否在面里:0
18:12:43.844 [main] INFO pers.stu.algorithm.IndexedPointInAreaLocatorUse - 是否在面里:1
18:12:43.844 [main] INFO pers.stu.algorithm.IndexedPointInAreaLocatorUse - 是否在面里:2