class GeometryMergeCommand implements CommandHasRequest<GeometryMergeRequest, GeometryMergeResponse> {

	@Override
	public void execute(GeometryMergeRequest request, GeometryMergeResponse response) throws Exception {
		List<org.geomajas.geometry.Geometry> clientGeometries = request.getGeometries();
		if (clientGeometries == null || clientGeometries.size() == 0) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "request");
		}
		if (clientGeometries.size() == 1) {
			response.setGeometry(clientGeometries.get(0));
			return;
		}
		int precision = request.getPrecision();

		List<Geometry> geometries = new ArrayList<Geometry>();
		for (org.geomajas.geometry.Geometry geometry : clientGeometries) {
			geometry.setPrecision(precision);
			geometries.add(converter.toInternal(geometry));
		}
		PrecisionModel precisionModel;
		if (precision == -1) {
			precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
			precision = 20;
		} else {
			precisionModel = new PrecisionModel(Math.pow(10.0, precision));
		}
		GeometryFactory factory = new GeometryFactory(precisionModel, geometries.get(0).getSRID());

		// Calculate the union:
		double buffer = 0;
		if (request.usePrecisionAsBuffer()) {
			buffer = Math.pow(10.0, -(precision - 1));
		}
		GeometryCollection geometryCollection = (GeometryCollection) factory.buildGeometry(geometries);

		Geometry union = geometryCollection.buffer(buffer);
		response.setGeometry(converter.toDto(union));
	}

}