The following sections explain how to manipulate Envelopes:
Creating an Envelope
Envelopes are essentially basic rectangles. Envelopes can be created directly from the GeometryBuilder, or if you only want to use GeoAPI interfaces you can use factories:
Using GeometryBuilder
The following example shows how to create an Envelope with the GeometryBuilder.
GeometryBuilder builder = new GeometryBuilder( DefaultGeographicCRS.WGS84 ); DirectPosition upper = builder.createDirectPosition(new double[]{-180,-90}); DirectPosition lower = builder.createDirectPosition(new double[]{180,90}); Envelope envelope = builder.createEnvelope( upper, lower );
Using Factories
Building an envelope from factories is very similar to the process of using the GeometryBuilder, but it lets you only use GeoAPI interfaces:
Hints hints = new Hints( Hints.CRS, DefaultGeographicCRS.WGS84 ); PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory( hints ); GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory( hints ); DirectPosition upper = positionFactory.createDirectPosition(new double[]{-180,-90}); DirectPosition lower = positionFactory.createDirectPosition(new double[]{180,90}); Envelope envelope = geometryFactory.createEnvelope( upper, lower );
Using the Envelope Width and Height
Width and Height are context dependent, what axis is "across" depends on the data you are working with. What you can do is ask for the "length" along an axis.
int length0= envelope.getLength( 0 ); int length1 = envelope.getLength( 1 );