我有一个几何对象的集合。现在我想从整个集合中计算最小边界矩形。 我正在使用Java拓扑套件,但我不知道该如何实现这一点?
请查看http://tsusiatsoftware.net/jts/javadoc/index.html
如果我假设您正在使用GeometryCollection实例。如果是这样,您可以直接调用:
geometry.getEnvelope();
或者geometry.getEnvelopeInternal();
如果您想要一个Envelope实例
它会返回GeometryCollection的最小矩形。
如果您有一组Geometries,可以直接使用Envelope,并在处理集合中的每个新几何体时扩展它。
Envelope env = new Envelope();
for(Geometry g : mySet){
env.expandToInclude(g.getEnvelopeInternal()):
}
或者Envelope env = new Envelope();
for(Geometry g : mySet){
env.expandToInclude(g.getBoundary().getEnvelopeInternal()):
}
我刚刚像这样组合了一个。
Geometry类有一个“getEnvelopeInternal()”方法,返回内部的包络线,但是“getEnvelope()”只返回另一个Geometry。
从javadoc中可以看出,返回的Geometry对象可能是:
查看其他关于Envelope的注释,我发现您可以“扩展”包络线...因此,这是我构建的用于转换的静态工具:
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;
}
我从未使用 jts,但是搜索到了以下内容:
遍历集合并对每个对象调用getBoundary().getEnvelopeInternal()
getEnvelopeInternal()
将忽略您几何图形的精度模型。 - Campa
getEnvelopeInternal()
会忽略您几何图形的精度模型。 - Campa