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()); 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)); }  @Override GeometryMergeRequest getEmptyCommandRequest(); @Override GeometryMergeResponse getEmptyCommandResponse(); @Override void execute(GeometryMergeRequest request, GeometryMergeResponse response);  }
@Test public void withPrecisionAsBufferTest() throws GeomajasException { GeometryMergeRequest request = new GeometryMergeRequest(); request.setGeometries(geometries); request.setPrecision(0); request.setUsePrecisionAsBuffer(true); GeometryMergeResponse response = (GeometryMergeResponse) dispatcher.execute( GeometryMergeRequest.COMMAND, request, null, "en"); Assert.assertEquals(3, response.getGeometry().getGeometries().length); }
@Test public void withoutPrecisionAsBufferTest() { GeometryMergeRequest request = new GeometryMergeRequest(); request.setGeometries(geometries); request.setPrecision(0); request.setUsePrecisionAsBuffer(false); GeometryMergeResponse response = (GeometryMergeResponse) dispatcher.execute( GeometryMergeRequest.COMMAND, request, null, "en"); Assert.assertEquals(1, response.getGeometry().getGeometries().length); }