JTS中基础的与空间操作相关的类
Coordinate 坐标(经纬度)操作类
A lightweight class used to store coordinates on the 2-dimensional Cartesian plane.一个轻量的类,被用来存储笛卡尔二维平面坐标。
构造方法
该类共有san个构造方法,可通过这些构造方法来进行对象的创建。
// 默认创建经度纬度为0的坐标点
public Coordinate() {
this(0.0D, 0.0D);
}
// 根据传入的x(经度)、y(维度),进行坐标点的创建
public Coordinate(double x, double y) {
this(x, y, 0.0D / 0.0);
}
// 根据传入的经度、维度、高度进行坐标点的创建
public Coordinate(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
创建示例:
也可通过get、set方法进行赋值。
Coordinate coordinate = new Coordinate(116.20,39.56);
主要方法
distance(计算两点间的欧式距离)
Computes the 2-dimensional Euclidean distance to another location. The Z-ordinate is ignored.计算两点之间二维平面的欧式距离,忽略z坐标。
注意:这里并不是指地图上两个经纬度之间的实际距离。
Coordinate coordinateStart = new Coordinate(116.20,39.56);
Coordinate coordinateEnd = new Coordinate(116.20,40.56);
double distance = coordinateStart.distance(coordinateEnd);
主要用法
用来创建坐标点
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate coordinate= new Coordinate(116.20,39.56);
Point point = geometryFactory.createPoint(coordinate);
Envelope(矩形区域)
JTS文档说明:Envelope
Defines a rectangular region of the 2D coordinate plane. It is often used to represent the bounding box of a Geometry, e.g. the minimum and maximum x and y values of the Coordinates.
定义二维坐标平面的矩形区域。它通常用于表示几何图形的边界框,例如坐标的最小和最大x和y值。
构造函数
//Creates a null Envelope.创建一个空的区域
Envelope()
//Creates an Envelope for a region defined by a single Coordinate.通过单个坐标点创建区域
Envelope(Coordinate p)
//Creates an Envelope for a region defined by two Coordinates.通过两个坐标点创建一个矩形区域
Envelope(Coordinate p1, Coordinate p2)
//Creates an Envelope for a region defined by maximum and minimum values.通过最小和最大的经纬度来创建一个矩形区域。x1,y1,x2,y2都为经纬度。
Envelope(double x1, double x2, double y1, double y2)
使用示例:
Coordinate leftDown = new Coordinate(116.20, 39.56);
Coordinate rightTop = new Coordinate(117.20,40.56);
Envelope envelope = new Envelope(leftDown,rightTop);
主要用法
构建一个矩形Geometry
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate leftDown = new Coordinate(116.20, 39.56);
Coordinate rightTop = new Coordinate(117.20,40.56);
Envelope envelope = new Envelope(leftDown,rightTop);
Geometry geometry = geometryFactory.toGeometry(envelope);