Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimal Bounding Rectangle with JTS

Tags:

java

jts

I've got a collection of geometry objects. Now i want to calculate the minimal bounding rectangle from the whole collection. i'm using the java topology suite, but I can't figure out how to do this?

like image 727
ABLX Avatar asked Feb 02 '23 10:02

ABLX


1 Answers

Have a look in http://tsusiatsoftware.net/jts/javadoc/index.html

If I assume you are using a GeometryCollection instance. If it's true, you can directly call

geometry.getEnvelope();

or

geometry.getEnvelopeInternal();

If you want an Envelope instance

It will return you the minimum rectangle of the GeometryCollection.

If you have a collection of Geometries, you can use an envelope directly, and expand it each time you process a new geometryc of your collection.

Envelope env = new Envelope();
for(Geometry g : mySet){
  env.expandToInclude(g.getEnvelopeInternal()):
}

or

Envelope env = new Envelope();
for(Geometry g : mySet){
  env.expandToInclude(g.getBoundary().getEnvelopeInternal()):
}
like image 184
Agemen Avatar answered Feb 12 '23 07:02

Agemen