@Test public void extendPointTest() throws Exception { CoordinateReferenceSystem crs; Coordinate coordinate; Envelope envelope; crs = geoService.getCrs("EPSG:900913"); coordinate = new Coordinate(0, 0); envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100); Assert.assertEquals(-100.00000376900834, envelope.getMinX(), DELTA); Assert.assertEquals(-50.33697512339748, envelope.getMinY(), DELTA); Assert.assertEquals(100.00000376900834, envelope.getMaxX(), DELTA); Assert.assertEquals(50.33697512339748, envelope.getMaxY(), DELTA); coordinate = new Coordinate(10000, 10000); envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100); Assert.assertEquals(9899.999874146251, envelope.getMinX(), DELTA); Assert.assertEquals(9949.6629648107, envelope.getMinY(), DELTA); Assert.assertEquals(10100.000125853749, envelope.getMaxX(), DELTA); Assert.assertEquals(10050.3370351893, envelope.getMaxY(), DELTA); crs = geoService.getCrs("EPSG:4326"); coordinate = new Coordinate(0, 0); envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100); Assert.assertEquals(-8.983152841199021E-4, envelope.getMinX(), DELTA); Assert.assertEquals(-4.5218473391466234E-4, envelope.getMinY(), DELTA); Assert.assertEquals(8.983152841199021E-4, envelope.getMaxX(), DELTA); Assert.assertEquals(4.5218473391466234E-4, envelope.getMaxY(), DELTA); coordinate = new Coordinate(100, 50); envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100); Assert.assertEquals(99.99860521715158, envelope.getMinX(), DELTA); Assert.assertEquals(49.99955048109636, envelope.getMinY(), DELTA); Assert.assertEquals(100.00139478284842, envelope.getMaxX(), DELTA); Assert.assertEquals(50.00044951890364, envelope.getMaxY(), DELTA); }
public Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs, double width, double height) throws GeomajasException { double halfCrsWidth = EXTEND_MAPUNIT_TEST_LENGTH; double halfCrsHeight = EXTEND_MAPUNIT_TEST_LENGTH; double x = coordinate.x; double y = coordinate.y; for (int i = EXTEND_MAX_ITERATIONS; i > 0; i--) { try { Coordinate test; test = new Coordinate(x + halfCrsWidth, y); double deltaX = JTS.orthodromicDistance(coordinate, test, crs); test = new Coordinate(x, y + halfCrsHeight); double deltaY = JTS.orthodromicDistance(coordinate, test, crs); if (Math.abs(deltaX - width / 2) < DISTANCE_PRECISION && Math.abs(deltaY - height / 2) < DISTANCE_PRECISION) { break; } halfCrsWidth = halfCrsWidth / deltaX * width / 2; halfCrsHeight = halfCrsHeight / deltaY * height / 2; } catch (TransformException te) { throw new GeomajasException(te, ExceptionCode.GEOMETRY_TRANSFORMATION_FAILED, crs); } } return new Envelope(x - halfCrsWidth, x + halfCrsWidth, y - halfCrsHeight, y + halfCrsHeight); }
GeocoderUtilService { public Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs, double width, double height) throws GeomajasException { double halfCrsWidth = EXTEND_MAPUNIT_TEST_LENGTH; double halfCrsHeight = EXTEND_MAPUNIT_TEST_LENGTH; double x = coordinate.x; double y = coordinate.y; for (int i = EXTEND_MAX_ITERATIONS; i > 0; i--) { try { Coordinate test; test = new Coordinate(x + halfCrsWidth, y); double deltaX = JTS.orthodromicDistance(coordinate, test, crs); test = new Coordinate(x, y + halfCrsHeight); double deltaY = JTS.orthodromicDistance(coordinate, test, crs); if (Math.abs(deltaX - width / 2) < DISTANCE_PRECISION && Math.abs(deltaY - height / 2) < DISTANCE_PRECISION) { break; } halfCrsWidth = halfCrsWidth / deltaX * width / 2; halfCrsHeight = halfCrsHeight / deltaY * height / 2; } catch (TransformException te) { throw new GeomajasException(te, ExceptionCode.GEOMETRY_TRANSFORMATION_FAILED, crs); } } return new Envelope(x - halfCrsWidth, x + halfCrsWidth, y - halfCrsHeight, y + halfCrsHeight); } }
GeocoderUtilService { public Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs, double width, double height) throws GeomajasException { double halfCrsWidth = EXTEND_MAPUNIT_TEST_LENGTH; double halfCrsHeight = EXTEND_MAPUNIT_TEST_LENGTH; double x = coordinate.x; double y = coordinate.y; for (int i = EXTEND_MAX_ITERATIONS; i > 0; i--) { try { Coordinate test; test = new Coordinate(x + halfCrsWidth, y); double deltaX = JTS.orthodromicDistance(coordinate, test, crs); test = new Coordinate(x, y + halfCrsHeight); double deltaY = JTS.orthodromicDistance(coordinate, test, crs); if (Math.abs(deltaX - width / 2) < DISTANCE_PRECISION && Math.abs(deltaY - height / 2) < DISTANCE_PRECISION) { break; } halfCrsWidth = halfCrsWidth / deltaX * width / 2; halfCrsHeight = halfCrsHeight / deltaY * height / 2; } catch (TransformException te) { throw new GeomajasException(te, ExceptionCode.GEOMETRY_TRANSFORMATION_FAILED, crs); } } return new Envelope(x - halfCrsWidth, x + halfCrsWidth, y - halfCrsHeight, y + halfCrsHeight); }  }
GeocoderUtilService { public Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs, double width, double height) throws GeomajasException { double halfCrsWidth = EXTEND_MAPUNIT_TEST_LENGTH; double halfCrsHeight = EXTEND_MAPUNIT_TEST_LENGTH; double x = coordinate.x; double y = coordinate.y; for (int i = EXTEND_MAX_ITERATIONS; i > 0; i--) { try { Coordinate test; test = new Coordinate(x + halfCrsWidth, y); double deltaX = JTS.orthodromicDistance(coordinate, test, crs); test = new Coordinate(x, y + halfCrsHeight); double deltaY = JTS.orthodromicDistance(coordinate, test, crs); if (Math.abs(deltaX - width / 2) < DISTANCE_PRECISION && Math.abs(deltaY - height / 2) < DISTANCE_PRECISION) { break; } halfCrsWidth = halfCrsWidth / deltaX * width / 2; halfCrsHeight = halfCrsHeight / deltaY * height / 2; } catch (TransformException te) { throw new GeomajasException(te, ExceptionCode.GEOMETRY_TRANSFORMATION_FAILED, crs); } } return new Envelope(x - halfCrsWidth, x + halfCrsWidth, y - halfCrsHeight, y + halfCrsHeight); }  Envelope transform(Envelope source, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs); Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs,
								double width, double height); }
GeocoderUtilService { public Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs, double width, double height) throws GeomajasException { double halfCrsWidth = EXTEND_MAPUNIT_TEST_LENGTH; double halfCrsHeight = EXTEND_MAPUNIT_TEST_LENGTH; double x = coordinate.x; double y = coordinate.y; for (int i = EXTEND_MAX_ITERATIONS; i > 0; i--) { try { Coordinate test; test = new Coordinate(x + halfCrsWidth, y); double deltaX = JTS.orthodromicDistance(coordinate, test, crs); test = new Coordinate(x, y + halfCrsHeight); double deltaY = JTS.orthodromicDistance(coordinate, test, crs); if (Math.abs(deltaX - width / 2) < DISTANCE_PRECISION && Math.abs(deltaY - height / 2) < DISTANCE_PRECISION) { break; } halfCrsWidth = halfCrsWidth / deltaX * width / 2; halfCrsHeight = halfCrsHeight / deltaY * height / 2; } catch (TransformException te) { throw new GeomajasException(te, ExceptionCode.GEOMETRY_TRANSFORMATION_FAILED, crs); } } return new Envelope(x - halfCrsWidth, x + halfCrsWidth, y - halfCrsHeight, y + halfCrsHeight); }  Envelope transform(Envelope source, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs); Envelope extendPoint(Coordinate coordinate, CoordinateReferenceSystem crs,
								double width, double height);  }