GeometryAreaCommand implements CommandHasRequest<GeometryAreaRequest, GeometryAreaResponse> { @Override public void execute(GeometryAreaRequest request, GeometryAreaResponse response) throws Exception { List<Double> areas = new ArrayList<Double>(request.getGeometries().size()); for (org.geomajas.geometry.Geometry g : request.getGeometries()) { Geometry geometry = converter.toInternal(g); double area = 0; if (geometry instanceof Polygonal) { if (request.getCrs() != null) { if (!EPSG_4326.equals(request.getCrs())) { geometry = geoService.transform(geometry, request.getCrs(), EPSG_4326); } geometry.apply(new CoordinateFilter() { public void filter(Coordinate coord) { double newX = coord.x * Math.PI / 180.0 * Math.cos(coord.y * Math.PI / 180.0); double newY = coord.y * Math.PI / 180.0; coord.x = newX; coord.y = newY; } }); area = geometry.getArea() * RADIUS * RADIUS; } else { area = geometry.getArea(); } } areas.add(area); } response.setAreas(areas); }  @Override GeometryAreaRequest getEmptyCommandRequest(); @Override GeometryAreaResponse getEmptyCommandResponse(); @Override void execute(GeometryAreaRequest request, GeometryAreaResponse response);  }
@Test public void areaTestNoCrs() throws GeomajasException { GeometryAreaRequest request = new GeometryAreaRequest(); request.setGeometries(geometries); GeometryAreaResponse response = (GeometryAreaResponse) dispatcher.execute(GeometryAreaRequest.COMMAND, request, null, "en"); List<Double> areas = response.getAreas(); Assert.assertEquals(4, areas.size()); Assert.assertEquals(25, areas.get(0), DELTA); Assert.assertEquals(0, areas.get(1), DELTA); Assert.assertEquals(0, areas.get(2), DELTA); Assert.assertEquals(90 * 180, areas.get(3), DELTA); }
@Test public void areaTestCrs() throws GeomajasException { GeometryAreaRequest request = new GeometryAreaRequest(); request.setGeometries(geometries); request.setGeometries(geometries); request.setCrs("EPSG:4326"); GeometryAreaResponse response = (GeometryAreaResponse) dispatcher.execute(GeometryAreaRequest.COMMAND, request, null, "en"); List<Double> areas = response.getAreas(); Assert.assertEquals(4, areas.size()); Assert.assertEquals(3.05094E11, areas.get(0), DELTA * 3.05094E11); Assert.assertEquals(0, areas.get(1), DELTA); Assert.assertEquals(0, areas.get(2), DELTA); Assert.assertEquals(1.278E14, areas.get(3), DELTA * 1.278E14); }