空间数据模型
(1)、JTS Geometry model 
(2)、ISO Geometry model (Geometry Plugin and JTS Wrapper Plugin)
GeoTools has two implementations of these interfaces:
Geometry Plugin a port of JTS 1.7 to the ISO Geometry interfaces

JTS Wrapper Plugin an implementation that delegates all the work to JTS

JTS包结构

系(linearref包)、计算交点(noding包)、几何图形操作(operation包)、平面图(planargraph包)、多边形化(polygnize包)、精度(precision)、工具(util包)

重点理解JTS Geometry model
(1) JTS提供了如下的空间数据类型
     Point     
     MultiPoint
     LineString     
     LinearRing  封闭的线条
     MultiLineString    多条线
     Polygon
     MultiPolygon

GeometryCollection  包括点,线,面

(2) 支持接口
Coordinate
   Coordinate(坐标)是用来存储坐标的轻便的类。它不同于点,点是Geometry的子类。不像模范Point的对象(包含额外的信息,例如一个信包,一个精确度模型和空间参考系统信息),Coordinate只包含纵座标值和存取方法。
Envelope(矩形)
   一个具体的类,包含一个最大和最小的x 值和y 值。
GeometryFactory
   GeometryFactory提供一系列的有效方法用来构造来自Coordinate类的Geometry对象。支持接口

import org.geotools.geometry.jts.JTSFactoryFinder;import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;/**  * Class GeometryDemo.java * Description Geometry 几何实体的创建,读取操作* Company mapbar * author Chenll E-mail: Chenll@mapbar.com* Version 1.0 * Date 2012-2-17 上午11:08:50*/
public class GeometryDemo {private GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );/*** create a point* @return*/public Point createPoint(){Coordinate coord = new Coordinate(109.013388, 32.715519);Point point = geometryFactory.createPoint( coord );return point;}/*** create a rectangle(矩形)* @return*/public Envelope createEnvelope(){Envelope envelope = new Envelope(0,1,0,2);return envelope;}/*** create a point by WKT* @return* @throws ParseException */public Point createPointByWKT() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );Point point = (Point) reader.read("POINT (109.013388 32.715519)");return point;}/*** create multiPoint by wkt* @return*/public MultiPoint createMulPointByWKT()throws ParseException{WKTReader reader = new WKTReader( geometryFactory );MultiPoint mpoint = (MultiPoint) reader.read("MULTIPOINT(109.013388 32.715519,119.32488 31.435678)");return mpoint;}/*** * create a line* @return*/public LineString createLine(){Coordinate[] coords  = new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)};LineString line = geometryFactory.createLineString(coords);return line;}/*** create a line by WKT* @return* @throws ParseException*/public LineString createLineByWKT() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );LineString line = (LineString) reader.read("LINESTRING(0 0, 2 0)");return line;}/*** create multiLine * @return*/public MultiLineString createMLine(){Coordinate[] coords1  = new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)};LineString line1 = geometryFactory.createLineString(coords1);Coordinate[] coords2  = new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)};LineString line2 = geometryFactory.createLineString(coords2);LineString[] lineStrings = new LineString[2];lineStrings[0]= line1;lineStrings[1] = line2;MultiLineString ms = geometryFactory.createMultiLineString(lineStrings);return ms;}/*** create multiLine by WKT* @return* @throws ParseException*/public MultiLineString createMLineByWKT()throws ParseException{WKTReader reader = new WKTReader( geometryFactory );MultiLineString line = (MultiLineString) reader.read("MULTILINESTRING((0 0, 2 0),(1 1,2 2))");return line;}/*** create a polygon(多边形) by WKT* @return* @throws ParseException*/public Polygon createPolygonByWKT() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");return polygon;}/*** create multi polygon by wkt* @return* @throws ParseException*/public MultiPolygon createMulPolygonByWKT() throws ParseException{WKTReader reader = new WKTReader( geometryFactory );MultiPolygon mpolygon = (MultiPolygon) reader.read("MULTIPOLYGON(((40 10, 30 0, 40 10, 30 20, 40 10),(30 10, 30 0, 40 10, 30 20, 30 10)))");return mpolygon;}/*** create GeometryCollection  contain point or multiPoint or line or multiLine or polygon or multiPolygon* @return* @throws ParseException*/public GeometryCollection createGeoCollect() throws ParseException{LineString line = createLine();Polygon poly =  createPolygonByWKT();Geometry g1 = geometryFactory.createGeometry(line);Geometry g2 = geometryFactory.createGeometry(poly);Geometry[] garray = new Geometry[]{g1,g2};GeometryCollection gc = geometryFactory.createGeometryCollection(garray);return gc;}/*** create a Circle  创建一个圆,圆心(x,y) 半径RADIUS* @param x* @param y* @param RADIUS* @return*/public Polygon createCircle(double x, double y, final double RADIUS){final int SIDES = 32;//圆上面的点个数Coordinate coords[] = new Coordinate[SIDES+1];for( int i = 0; i < SIDES; i++){double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;double dx = Math.cos( angle ) * RADIUS;double dy = Math.sin( angle ) * RADIUS;coords[i] = new Coordinate( (double) x + dx, (double) y + dy );}coords[SIDES] = coords[0];LinearRing ring = geometryFactory.createLinearRing( coords );Polygon polygon = geometryFactory.createPolygon( ring, null );return polygon;}/*** @param args* @throws ParseException */public static void main(String[] args) throws ParseException {GeometryDemo gt = new GeometryDemo();Polygon p = gt.createCircle(0, 1, 2);//圆上所有的坐标(32个)Coordinate coords[] = p.getCoordinates();for(Coordinate coord:coords){System.out.println(coord.x+","+coord.y);}Envelope envelope = gt.createEnvelope();System.out.println(envelope.centre());}
}

JTS(Geometry)工具类相关推荐

  1. java解析shp文件以及坐标转换(工具类)

    百度找了很多大部分都是pom的,maven项目中的,但是用maven下载不了,只能一个jar一个jar下载了,中间也遇到了很多坑,都是pom中没有提到的架包 直接上代码,最后我会解析shp文件所用到的 ...

  2. 实战SSM_O2O商铺_08【商铺注册】Thumbnailator图片处理和封装工具类

    文章目录 概述 Thumbnailator 简介 工具类的封装 Step1 添加maven依赖 Step2 FileUtil.java Step3 ImageUtil.java Github地址 概述 ...

  3. Java实现Google的S2算法工具类

    WGS84坐标系 GCJ02坐标系 BD09坐标系的各种转换 WGS84坐标系 GCJ02坐标系 BD09坐标系的各种转换 Google S2 经纬度 转 CellId 经纬度 转 cellToken ...

  4. objectArx --- 工具类

    目录 一.转换类 二.数学计算类 三.几何计算类 四.字符串工具类 4.1 类定义 4.2 测试代码 五.文件操作类 5.1 类定义 5.2 测试代码 一.转换类 功能:显式转换不同数据类型 筛选器O ...

  5. 对象存储Minio 客户端工具类,实现文件上传、图像压缩、图像添加水印

    在搭建好了MInio分布式对象存储集群后,官方提供了MInio Client 各类语言的SDK,但是无法直接使用需要进一步封装,这里将JAVA 版的的SDK结合自身业务做个简单封装. Minio 中文 ...

  6. Vue-一些常用的工具类

    本文介绍一些常用的工具类 1.验证码 如下图,一般的后台管理系统都会在登录的时候设计一个验证码,这个验证码是前端生成的,点击canvas可以切换验证码.二维码的类型是数字或者字母自己可以根据需要设置, ...

  7. EsriJSON与GeoJSON转换工具类

    EsriJSON与GeoJSON转换工具类.简单的点线面应该没问题,复杂的可能有问题,没具体测试.大家可以在这个基础上修改.后面用起来慢慢修正吧.package piesat.geo;import c ...

  8. java图片压缩(谷歌工具类)

    引入jar依赖 <dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailato ...

  9. 使用open3d加载点云数据工具类

    设计思路: 将点云文件加载成tensor类型,用于PointNet进行处理. 将tensor类型的点云文件保存到指定的位置 将点云数据可视化 类似于ply类型的点云文件,使用open3d读入之后,类型 ...

最新文章

  1. Kubernetes Service 对象的使用
  2. ansible代码发布系统
  3. 以下选项不是python打开方式的是-以下选项,不是Python保留字的选项是:_学小易找答案...
  4. 用python pandas按块读取超大csv/txt
  5. Thinkpad产品预装Win7系统一键恢复方法介绍
  6. len()与cap()的区别
  7. Python使用psutil模块,做你的电脑管家
  8. 201700071045.md
  9. day16-17-18.对象序列化和反序列化、API获取数据、python操作Excel/CSV文件、类、面向对象编程(初级及进阶)、继承
  10. 记录我的LINUX学习之路
  11. 台湾半导体制造商台积电市值首次超越英特尔
  12. MikTex 和 TexStudio 输入中文日文
  13. 计算机中pdf怎么预览,如何在浏览器中开启PDF时默认显示Adobe Reader XI工具栏
  14. 微信支付分支付免押订单租赁订单thinkphp5
  15. LeetCode——第121题:买股票的最佳时机
  16. 智慧环保-污水处理远程监控解决方案
  17. 100行Python代码,做一个打地鼠小游戏
  18. hive 和 Hadoop 浅析
  19. 中标麒麟OS连接win10上的SMB共享
  20. 员工上网行为管理——一把怎样的双刃剑

热门文章

  1. linux下ftp服务和dns的关系,linux企业常用服务---dns+ftp+dhcp
  2. Markdown文档如何分页以及导出的PDF如何分页
  3. Leetcode每日一题:29.divide-two-integers(两数相除)
  4. Data Lake Analytics: 基于OSS文件自动推断建表
  5. git 入门教程之 git 私服搭建教程
  6. python pca双标图的含义_PCA双标图 - 箭长度
  7. sublime java 编译_03 sublime text3下配置Java的编译运行环境
  8. 海信计算机怎么开机,将海信电视连接到计算机的步骤_计算机的基本知识_IT /计算机_信息...
  9. zookeper安装_zookeeper安装单机模式
  10. 由于找不到Qt5widgets.dll,无法继续执行代码。重新安装程序可能会解决此问题。