Geometry

一、几何对象模型概述

        独立于计算机平台之外的、天然适用于分布式计算的、统一使用建模语言表示的一种对象模型。几何对象模型类图如下:

二、几何对象模型分类

        几何对象模型大致可以分为3类:简单数据模型、集合数据模型、曲线和曲面数据模型

1、简单数据模型

        1.1 点数据模型(Point、MultiPoint)

        1.2 多段线数据模型(线段 | LineString、直线 | Line、线性环 | LineRing、多重多段线 | MultiLineString)

        1.3 多边形数据模型(Polygon)

        1.4 多面体表面对象(PolyhedralSurface)

2、集合数据模型

        2.1 几何对象集合(GeometryCollection)

        2.2 曲面几何对象集合(MultiSurface)

        2.3 多边形几何对象集合(MultiPolygon)

        2.4 曲线几何对象集合(MultiCurve)

3、曲线和曲面数据模型

        3.1 曲线数据模型(Curve)

        3.2 曲面数据模型(Surface)

三、几何对象的WKT表示

        WKT(Well-known text)是一种文本标记语言,用于表示矢量几何对象、**空间参照系统**及空间参照系统之间的转换。它的二进制表示方式,亦即WKB(well-known binary)则胜于在传输和在数据库中存储相同的信息。该格式由开放地理空间联盟(OGC)制定。

四、几何对象创建

1、创建单点(Point)

1.1 通过坐标对象Coordinate创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(1, 1);
Point point = geometryFactory.createPoint(coord);

1.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Point point = (Point) reader.read("POINT (1 1)");

2、创建多点(MultiPoint)

2.1 通过CoordinateSequence创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
CoordinateSequence coordinateSequence = new CoordinateSequence2D(1, 1,2,2,3,3);
MultiPoint multiPoint = geometryFactory.createMultiPoint(coordinateSequence);

2.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
MultiPoint multiPoint = (MultiPoint) reader.read("MULTIPOINT(1 1,2 2,3 3)");

3、创建线段(LineString)

3.1 通过Coordinate创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords = new Coordinate[] {new Coordinate(0, 2), new Coordinate(2, 0), new Coordinate(8, 6) };
LineString line = geometryFactory.createLineString(coordinates);

3.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");

4、创建多重多线段(MultiLineString)

4.1 通过LineString[ ]创建

Coordinate[] coords  = new Coordinate[] {new Coordinate(2, 2), new Coordinate(3, 3)};
LineString lineString = geometryFactory.createLineString(coords);
Coordinate[] coords1  = new Coordinate[] {new Coordinate(3, 3), new Coordinate(4, 4)};
LineString lineString1 = geometryFactory.createLineString(coords1);

LineString[] lineStrings = new LineString[]{lineString, lineString1};
MultiLineString multiLineString = geometryFactory.createMultiLineString(lineStrings);

4.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
MultiLineString multiLineString = (MultiLineString) reader.read("MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))");

5、创建单面(Polygon | 多边形)

5.1 通过Coordinate创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords  =  new Coordinate[] {new Coordinate(4, 0), new Coordinate(2, 2),                     												 new Coordinate(4, 4), new Coordinate(6, 2), new Coordinate(4, 0) };
LinearRing ring = geometryFactory.createLinearRing( coords );
LinearRing holes[] = null; Polygon polygon = geometryFactory.createPolygon(ring, holes );

5.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");

6、创建多面(MultiPolygon)

6.1 通过Polygon[ ] 创建

GeometryFactory#createMultiPolygon(Polygon[])

6.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
MultiPolygon multiPolygon = (MultiPolygon) reader.read("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6 3)))");

五、Geometry操作方法

1、几何关系判断(返回值 boolean)

2、几何关系分析(返回值 几何对象)

2.1 buffer(缓冲区分析)

public Geometry buffer(double distance);

 distance 参数:缓冲区扩展的距离(可以是正数(向外扩展)、负数(向内扩展)或 0(边界))。示意图如下(注:绿色线代表扩展之后的):

2.2 intersection(交叉分析)

public Geometry intersection(Geometry other);

 geometryA.intersection(geometryB):获取两个几何体之间的交叉部分的几何体

2.3 convexHull(凸壳分析)

包含几何形体的所有点的最小凸壳多边形(外包多边形)。示意图如下:

2.4 union(联合分析)

获取多面体所有点的集合。示意图如下:

2.5 difference(差异分析)

获取一个多面体里有,另一个多面体里没有的点的集合。示意图如下:

2.6 symDifference(对称差异分析)

不同时在两个多面体中的所有点的集合。示意图如下:

  • 26
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值