JTS Geometry关系判断和分析
关系判断
- Geometry之间的关系有如下几种:
相等(Equals): |
几何形状拓扑上相等。 |
脱节(Disjoint): |
几何形状没有共有的点。 |
相交(Intersects): |
几何形状至少有一个共有点(区别于脱节) |
接触(Touches): |
几何形状有至少一个公共的边界点,但是没有内部点。 |
交叉(Crosses): |
几何形状共享一些但不是所有的内部点。 |
内含(Within): |
几何形状A的线都在几何形状B内部。 |
包含(Contains): |
几何形状B的线都在几何形状A内部(区别于内含) |
重叠(Overlaps): |
几何形状共享一部分但不是所有的公共点,而且相交处有他们自己相同的区域。 |
- 如下例子展示了如何使用Equals,Disjoint,Intersects,Within操作:
package com.alibaba.autonavi;import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;/*** gemotry之间的关系* @author xingxing.dxx**/
public class GeometryRelated {private GeometryFactory geometryFactory = new GeometryFactory();/*** 两个几何对象是否是重叠的* @return* @throws ParseException*/public boolean equalsGeo() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );LineString geometry1 = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");LineString geometry2 = (LineString) reader.read("LINESTRING(5 0, 0 0)");return geometry1.equals(geometry2);//true}/*** 几何对象没有交点(相邻)* @return* @throws ParseException*/public boolean disjointGeo() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );LineString geometry1 = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");LineString geometry2 = (LineString) reader.read("LINESTRING(0 1, 0 2)");return geometry1.disjoint(geometry2);}/*** 至少一个公共点(相交)* @return* @throws ParseException*/public boolean intersectsGeo() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );LineString geometry1 = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");LineString geometry2 = (LineString) reader.read("LINESTRING(0 0, 0 2)");Geometry interPoint = geometry1.intersection(geometry2);//相交点System.out.println(interPoint.toText());//输出 POINT (0 0)return geometry1.intersects(geometry2);}/*** 判断以x,y为坐标的点point(x,y)是否在geometry表示的Polygon中* @param x* @param y* @param geometry wkt格式* @return*/public boolean withinGeo(double x,double y,String geometry) throws ParseException {Coordinate coord = new Coordinate(x,y);Point point = geometryFactory.createPoint( coord );WKTReader reader = new WKTReader( geometryFactory );Polygon polygon = (Polygon) reader.read(geometry);return point.within(polygon);}/*** @param args* @throws ParseException */public static void main(String[] args) throws ParseException {GeometryRelated gr = new GeometryRelated();System.out.println(gr.equalsGeo());System.out.println(gr.disjointGeo());System.out.println(gr.intersectsGeo());System.out.println(gr.withinGeo(5,5,"POLYGON((0 0, 10 0, 10 10, 0 10,0 0))"));}}
关系分析
- 关系分析有如下几种
缓冲区分析(Buffer) |
包含所有的点在一个指定距离内的多边形和多多边形 |
凸壳分析(ConvexHull) |
包含几何形体的所有点的最小凸壳多边形(外包多边形) |
交叉分析(Intersection) |
A∩B 交叉操作就是多边形AB中所有共同点的集合 |
联合分析(Union) |
AUB AB的联合操作就是AB所有点的集合 |
差异分析(Difference) |
(A-A∩B) AB形状的差异分析就是A里有B里没有的所有点的集合 |
对称差异分析(SymDifference) |
(AUB-A∩B) AB形状的对称差异分析就是位于A中或者B中但不同时在AB中的所有点的集合 |
2. 我们来看看具体的例子
package com.alibaba.autonavi;import java.util.ArrayList;
import java.util.List;import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;/*** gemotry之间的关系分析** @author xingxing.dxx*/
public class Operation {private GeometryFactory geometryFactory = new GeometryFactory();/*** create a Point** @param x* @param y* @return*/public Coordinate point(double x, double y) {return new Coordinate(x, y);}/*** create a line** @return*/public LineString createLine(List<Coordinate> points) {Coordinate[] coords = (Coordinate[]) points.toArray(new Coordinate[points.size()]);LineString line = geometryFactory.createLineString(coords);return line;}/*** 返回a指定距离内的多边形和多多边形** @param a* @param distance* @return*/public Geometry bufferGeo(Geometry a, double distance) {return a.buffer(distance);}/*** 返回(A)与(B)中距离最近的两个点的距离** @param a* @param b* @return*/public double distanceGeo(Geometry a, Geometry b) {return a.distance(b);}/*** 两个几何对象的交集** @param a* @param b* @return*/public Geometry intersectionGeo(Geometry a, Geometry b) {return a.intersection(b);}/*** 几何对象合并** @param a* @param b* @return*/public Geometry unionGeo(Geometry a, Geometry b) {return a.union(b);}/*** 在A几何对象中有的,但是B几何对象中没有** @param a* @param b* @return*/public Geometry differenceGeo(Geometry a, Geometry b) {return a.difference(b);}public static void main(String[] args) {Operation op = new Operation();//创建一条线List<Coordinate> points1 = new ArrayList<Coordinate>();points1.add(op.point(0, 0));points1.add(op.point(1, 3));points1.add(op.point(2, 3));LineString line1 = op.createLine(points1);//创建第二条线List<Coordinate> points2 = new ArrayList<Coordinate>();points2.add(op.point(3, 0));points2.add(op.point(3, 3));points2.add(op.point(5, 6));LineString line2 = op.createLine(points2);System.out.println(op.distanceGeo(line1, line2));//out 1.0System.out.println(op.intersectionGeo(line1, line2));//out GEOMETRYCOLLECTION EMPTYSystem.out.println(op.unionGeo(line1, line2)); //out MULTILINESTRING ((0 0, 1 3, 2 3), (3 0, 3 3, 5 6))System.out.println(op.differenceGeo(line1, line2));//out LINESTRING (0 0, 1 3, 2 3)}
}
JTS Geometry关系判断和分析相关推荐
- JTS Geometry
JTS Geometry关系判断和分析 JTS Geometry关系判断和分析 1.关系判断 1.1实例 2.关系分析 2.1实例 JTS(Geometry) JTS Geometry关系判断和分析 ...
- JTS 空间数据关系分析
JTS Geometry关系分析: 分析类型 含义 缓冲区分析(Buffer) 包含所有的点在一个指定距离内的多边形和多多边形 凸壳分析(ConvexHull) 包含几何形体的所有点的最小凸壳多边形( ...
- GeoTools应用-JTS(Geometry之间的关系)
几何信息和拓扑关系是地理信息系统中描述地理要素的空间位置和空间关系的不可缺少的基本信息.其中几何信息主要涉及几何目标的坐标位置.方向.角度.距离和面积等信息,它通常用解析几何的方法来分析.而空间关系信 ...
- R语言中通过鞅残差(martingale residual)分析、可视化自变量与鞅残差的关系判断指定连续变量和风险比HR值是否存在着线性趋势、Cox回归对线性条件的诊断
R语言中通过鞅残差(martingale residual)分析.可视化自变量与鞅残差的关系判断指定连续变量和风险比HR值是否存在着线性趋势.Cox回归对线性条件的诊断 目录
- 基于R树索引的点面关系判断以及效率优化统计
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 在之前的博客中,我分别介绍了基于网格的空间索引(http:// ...
- 最全面的homogeneous单应性坐标的定义,以及不同投影,仿射,相似,刚体变换矩阵的关系和自由度分析
本文对图像的投影变换,做了最基础和全面的总结.包括了摄影几何,homogeneous单应性坐标与变换矩阵分析. 1. Homogeneous Coordinate的定义 2. 使用Homogeneou ...
- JTS(Geometry)工具类
空间数据模型 (1).JTS Geometry model (2).ISO Geometry model (Geometry Plugin and JTS Wrapper Plugin) GeoTo ...
- 数据仓库、OLAP和 数据挖掘、统计分析的关系和区别分析 .
数据仓库.OLAP和 数据挖掘.统计分析的关系和区别分析 一.什么是数据挖掘 数据挖掘(Data Mining),又称为数据库中的知识发现(Knowledge Discovery in Databas ...
- 车身坐标系与大地坐标系中速度、加速度转换关系推导与分析
车身坐标系与大地坐标系中速度.加速度转换关系推导与分析 在不同的坐标系中,向量的大小和方向都是不变的,但是可以根据不同的坐标系将向量描述成不同的结果. 图1 车身坐标系与大地坐标系速度转换 已 ...
最新文章
- java foreach delete_Java CopyOnWriteArrayList forEach()用法及代码示例
- 找出字符串中所有数字
- Linux学习笔记 Day 4~5
- 矩阵快速幂---BestCoder Round#8 1002
- ylbtech-LanguageSamples-SimpleVariance
- 转载,关于缓存穿透、缓存并发、缓存雪崩那些事
- Mac最常用快键键持续更新ing
- Eclipse中Java Web开发插件安装
- 为什么会有宇宙?宇宙之外会有什么?
- 哈工大期末考试java_哈尔滨工业大学2019算法设计期末试题
- macbook快捷键_MacBook 键盘的「fn」键有什么用
- 博商零售业网上商店系统解决方案
- 计算机PS考试都考哪些,计算机专业ps考试题(考查课)(10页)-原创力文档
- WPS删除多余空白页
- netcfg.hlp 官方版
- 近几年美国人口数据matlab,【美国人口2018总人数】美国人口数量2018|美国人口世界排名...
- 零基础入门数据挖掘-Task3 特征工程
- ubuntu | 用crossover安装-微信和企业微信
- Vue报错Duplicate keys found unique.
- 2021图机器学习有哪些新突破?麦吉尔大学博士后一文梳理展望领域趋势
热门文章
- python函数降低编程复杂度_Python重构此函数,将其认知复杂度从19降低到允许的15...
- python拖拽获取文件路径_求助tkinter模块如何获取拖拽文件的内容
- 正点原子操作过程中芯片总是出错
- Java自动化测试框架-02 - TestNG之理论到实践 - (详细教程)
- linux能运行安卓模拟器吗,Ubuntu 14.04中使用模拟器运行Android系统
- 考上985能改变命运吗_2021艺考生:文化课成绩一般,有机会考上985、211吗?
- php学到什么程度可以学thinkphp,thinkphp学习一
- JS, CSS 文件压缩与反压缩工具
- Javascript图形处理库 -- Raphaël
- Windows操作系统的各进程的作用