@Test public void testCheckCoordinateRange() throws Exception { DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84; // valid JTS.checkCoordinatesRange(JTS.toGeometry(new Envelope(-10, 10, -10, 10)), crs); // invalid lat try { JTS.checkCoordinatesRange(JTS.toGeometry(new Envelope(-10, 10, -100, 10)), crs); fail("Provided invalid coordinates, yet check did not throw an exception"); } catch (PointOutsideEnvelopeException e) { // fine } // invalid lon try { JTS.checkCoordinatesRange(JTS.toGeometry(new Envelope(-190, 10, -10, 10)), crs); fail("Provided invalid coordinates, yet check did not throw an exception"); } catch (PointOutsideEnvelopeException e) { // fine } }
/** * Checks that all features coordinates are within the expected coordinate range * * @param collection * @throws PointOutsideEnvelopeException */ void checkFeatureCoordinatesRange(SimpleFeatureCollection collection) throws PointOutsideEnvelopeException { List types = collection.getSchema().getAttributeDescriptors(); SimpleFeatureIterator fi = collection.features(); try { while (fi.hasNext()) { SimpleFeature f = fi.next(); for (int i = 0; i < types.size(); i++) { if (types.get(i) instanceof GeometryDescriptor) { GeometryDescriptor gat = (GeometryDescriptor) types.get(i); if (gat.getCoordinateReferenceSystem() != null) { Geometry geom = (Geometry) f.getAttribute(i); if (geom != null) JTS.checkCoordinatesRange(geom, gat.getCoordinateReferenceSystem()); } } } } } finally { fi.close(); } }
if (crs != null) try { JTS.checkCoordinatesRange(geometry, crs); } catch (PointOutsideEnvelopeException e) { throw new WFSException(e, "InvalidParameterValue");
JTS.checkCoordinatesRange(geometry, source != null ? source : target);