Java JTS最小包围矩形
我收集了一些几何体对象。现在我想从整个集合中计算最小边界矩形。Java JTS最小包围矩形,java,jts,Java,Jts,我收集了一些几何体对象。现在我想从整个集合中计算最小边界矩形。 我正在使用java拓扑套件,但我不知道如何做到这一点?我从未使用过jts,但谷歌搜索了以下内容: 遍历集合,并为每个对象调用getBoundary()。getEnvelopeInternal()查看 如果我假设您使用的是GeometryCollection实例。如果是真的,你可以直接打电话 geometry.getEnvelope(); 或 如果需要信封实例 它将返回GeometryCollection的最小矩形 Envelope
我正在使用java拓扑套件,但我不知道如何做到这一点?我从未使用过jts,但谷歌搜索了以下内容: 遍历集合,并为每个对象调用
getBoundary()。getEnvelopeInternal()
查看
如果我假设您使用的是GeometryCollection实例。如果是真的,你可以直接打电话
geometry.getEnvelope();
或
如果需要信封实例
它将返回GeometryCollection的最小矩形
Envelope env = new Envelope();
for(Geometry g : mySet){
env.expandToInclude(g.getEnvelopeInternal()):
}
如果有几何图形集合,则可以直接使用封套,并在每次处理集合的新几何图形时将其展开
Envelope env = new Envelope();
for(Geometry g : mySet){
env.expandToInclude(g.getEnvelopeInternal()):
}
或
我只是把一个像这样放在一起 Geometry类有一个“getEnvelopeInternal()”返回内切信封,但“getEnvelope()”只返回另一个几何体 查看javadoc,返回的几何体对象可能是:
public static Envelope enclosingEnvelopFromGeometry(Geometry geometry) {
final Envelope envelope = new Envelope();
final Geometry enclosingGeometry = geometry.getEnvelope();
final Coordinate[] enclosingCoordinates = enclosingGeometry.getCoordinates();
for (Coordinate c : enclosingCoordinates) {
envelope.expandToInclude(c);
}
return envelope;
}
嗯,你用谷歌搜索了哪个词?你能给我官方文档中的链接吗:,几何和信封类。这不是官方文档。VictorSolution不是上一个JTS版本的维护者。请注意,
getEnvelopeInternal()
将忽略几何体的精度模型。getEnvelopeInternal()
将忽略几何体的精度模型。
public static Envelope enclosingEnvelopFromGeometry(Geometry geometry) {
final Envelope envelope = new Envelope();
final Geometry enclosingGeometry = geometry.getEnvelope();
final Coordinate[] enclosingCoordinates = enclosingGeometry.getCoordinates();
for (Coordinate c : enclosingCoordinates) {
envelope.expandToInclude(c);
}
return envelope;
}