gpt4 book ai didi

java - Geotools:wgs84 中缓冲区的边界框

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:04 47 4
gpt4 key购买 nike

我需要一个 Java 函数来生成围绕缓冲区的边界框(矩形)。缓冲区由中心点(WGS84 坐标)和半径(以米为单位)定义。

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

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

然而,这是纯平面几何。有没有办法使用以米为单位的距离坐标引用系统来做到这一点?

最适合 Geotools,但其他 Java 解决方案也可以...

最佳答案

尽管您采用了另一种方法,但我有另一种解决方案。结果将比您提出的解决方案更精确。

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);
}

这是带有结果的 map ,红色缓冲区,黑色信封。

Buffer and envelope

关于java - Geotools:wgs84 中缓冲区的边界框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36455020/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com