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);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值