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.0
System.out.println(op.intersectionGeo(line1, line2));//out GEOMETRYCOLLECTION EMPTY
System.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关系判断和分析 ...
- 基于R树索引的点面关系判断以及效率优化统计
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 在之前的博客中,我分别介绍了基于网格的空间索引(http:// ...
- JTS(Geometry)(转)
原文链接:http://blog.csdn.net/cdl2008sky/article/details/7268577 空间数据模型(1).JTS Geometry model (2).ISO Ge ...
- NLP之基于BERT的预测掩码标记和句间关系判断
BERT @ 目录 BERT 程序步骤 程序步骤 设置基本变量值,数据预处理 构建输入样本 在样本集中随机选取a和b两个句子 把ab两个句子合并为1个模型输入句,在句首加入分类符CLS,在ab中间和句 ...
- Geometry关系高级操作
一些高级的操作 几何形状Geometry缓冲(buffer) 线段的融合(linemerge)是将Geometry A中相互连接的线段进行连接 多边形化操作(polygonize)对Geometry ...
- Python基础(三):简化除法判断、分析apache访问日志、扫描存活主机、利用多线程实现ssh并发访问
一.简化除法判断 目标: 编写mydiv.py脚本,主要要求如下: 提示用户输入一个数字作为除数 如果用户按下Ctrl+C或Ctrl+D则退出程序 如果用户输入非数字字符,提示用户应该输入数字 如果用 ...
- C:矩形相交、相包含、相离关系判断
矩形相交 包含 问题.参考 假定矩形是用一对点表达的(minx, miny) (maxx, maxy),那么两个矩形 rect1{(minx1, miny1)(maxx1, maxy1)} ...
- Mybatis日期类型的关系判断
进行时间段的查询时,在mapper文件中直接使用">","<"等关系运算符是无法解析的 <if test="executeStart ...
- boost::algorithm用法详解之字符串关系判断
http://blog.csdn.net/qingzai_/article/details/44417937 下面先列举几个常用的: #define i_end_with boost::iends_w ...
随机推荐
- Vbox如何修改虚拟机器的uuid
先是 X: 然后cd X:\Program Files\VirtualBox 然后是 VBoxManage internalcommands sethduuid "X:\Progra ...
- Go语言获取项目当前路径
package main import ( "fmt" "os" "os/exec" "strings" ) func ...
- 关于html、asp、php模板引擎、aspnet mvc、REST的一点思考
先看我对REST的一点认识,下面是<rest实战> 这本书的序言文字: 在我刚刚开始从事解决计算问题的时候,业界就有很多人有一个愿望:将系统设计为能够被自由组合的组件.互联网(I ...
- 二叉树系列 - 二叉搜索树 - 线性时间内把有序链表转化为BST
引言 本文来自于Google的一道题目: how to merge two binary search tree into balanced binary search tree. how to me ...
- Sublime Text3 插件集合
下载地址:http://download.csdn.net/detail/yinluhui/9029791 [包含的插件有: AndyJS2.BracketHighlighter.emmet-subl ...
- SPI总线通信电路设计
数据带宽=(总线频率×数据位宽)÷8 B表示带宽,F表示存储器时钟频率,D表示存储器数据总线位数,则带宽为: B(峰值带宽)=F(时钟频率MHz)×D(总线位数bit)/8 例如,PC-100的SDR ...
- webgame设计之功能模块的代理模式
原文地址:http://chengduyi.com/blog/?post=27 在游戏设计中,通常会将一些实现了具体功能的模块进行封装,达到重用的目的.这些功能模块包括:1.网络通信模块(实现连接,断 ...
- Sass学习之路:Sass、Compass安装与命令行
导言 CSS不是一门真正意义上的编程语言,很多编程语言理所当然的特性(比如变量),都不被支持.同时再开发模块化的web项目的时候,也要避免相互干扰.为了弥补CSS的这些不足,就产生了CSS预处理器,S ...
- 【Java】一次SpringMVC+ Mybatis 配置多数据源经历
需求 现在在维护的是学校的一款信息服务APP的后台,最近要开发一些新功能,其中一个就是加入学校电影院的在线购票.在线购票实际上已经有一套系统了,但是是外包给别人开发的,我们拿不到代码只能拿到数据库,并 ...
- 使用即时文件初始化提高SQL Server性能
今天我想谈下SQL Server里的一个特别话题——即时文件初始化(Instant File Initialization).对于你的SQL Server实例,如果你启用了即时文件初始化,在特定情况下 ...