class 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);
					}
					// applying global sinusoidal projection (equal-area)
					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);
	}

}