Geotools:wgs84中缓冲区的边界框 [英] Geotools: bounding box for a buffer in wgs84

查看:493
本文介绍了Geotools:wgs84中缓冲区的边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Java函数,该函数将在缓冲区周围生成一个边界框(矩形).缓冲区由中心点(WGS84坐标)和半径(以米为单位)定义.

I am need a Java function that will generate a bounding box (rectangle) around a buffer. The buffer is defined by the center point (WGS84 coordinate) and the radius (in meters).

在JTS中为缓冲区获取边界框似乎很简单:

Getting a bounding box for a buffer in JTS seems to be quite simple:

Point center = ....
Geometry boundingBox = center.buffer(...).getEnvelope();

这是纯平面几何.有没有办法使用以米为单位的距离的坐标参考系来做到这一点?

This however is pure planar geometry. Is there a way to do this using a coordinate reference system with the distance given in meters?

最适合与Geotools一起使用,但其他Java解决方案也可以使用...

Optimally with Geotools but other Java solutions will also work...

推荐答案

尽管您以其他方式进行了处理,但我对此有另一种解决方案.结果将比您提出的解决方案更加精确.

Although you have approached it in another way, I have another solution for that. The results will be way more precise than with your proposed solution.

GeometryFactory GEOMETRY_FACTORY = JTSFactoryFinder.getGeometryFactory();

// Remember, order is (longitude, latitude)
Coordinate center = Coordinate(2.29443, 48.85816);
Point point = GEOMETRY_FACTORY.createPoint(center);

// Buffer 50KM around the point, then get the envelope
Envelope envelopeInternal = buffer(point, 50000).getEnvelopeInternal();

// Then you can play with the envelope, e.g.,
double minX = envelopeInternal.getMinX();
double maxX = envelopeInternal.getMaxX();

// The buffer using distanceInMeters
private Geometry buffer(Geometry geometry, double distanceInMeters) throws FactoryException, TransformException {
     String code = "AUTO:42001," + geometry.getCentroid().getCoordinate().x + "," + geometry.getCentroid().getCoordinate().y;
     CoordinateReferenceSystem auto = CRS.decode(code);

     MathTransform toTransform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, auto);
     MathTransform fromTransform = CRS.findMathTransform(auto, DefaultGeographicCRS.WGS84);

     Geometry pGeom = JTS.transform(geometry, toTransform);
     Geometry pBufferedGeom = pGeom.buffer(distanceInMeters);
     return JTS.transform(pBufferedGeom, fromTransform);
}

这是结果的地图,红色为缓冲区,黑色为信封.

And here is the map with the result, buffer in red, envelope in black.

这篇关于Geotools:wgs84中缓冲区的边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆