> 文章列表 > JTS几何面的中心点不一定在几何体上

JTS几何面的中心点不一定在几何体上

JTS几何面的中心点不一定在几何体上

JTS几何面的中心点不一定在几何体

实验

1、在JTS TestBuilder上画一个月亮形状的面积

JTS几何面的中心点不一定在几何体上

2、用java代码获取中心点

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;public class Test {public static void main(String[] args) throws ParseException {String xin_0="POLYGON ((113.03925000000001 22.953510000000005, 113.03923666666667 22.953516666666665, 113.03921666666666 22.95352, 113.03915666666667 22.953533333333333, 113.03914333333333 22.953533333333333, ......))";Geometry geometry0 = GeometryUtil.readGeometry(xin_0);System.out.println(geometry0.getCentroid().getX());System.out.println(geometry0.getCentroid().getY());}}

输出结果:

113.0386093933024
22.95282839698736

3、结论

如上图,中心点为黄色圆圈部分,在中心点外面。

4、补充

JTS TestBuilder 下载地址
JTS TestBuilder 下载地址二