GeometryBufferCommand implements CommandHasRequest<GeometryBufferRequest, GeometryBufferResponse> { @Override public void execute(GeometryBufferRequest request, GeometryBufferResponse response) throws Exception { List<org.geomajas.geometry.Geometry> clientGeometries = request.getGeometries(); if (clientGeometries == null || clientGeometries.size() == 0) { throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "request"); } List<org.geomajas.geometry.Geometry> result = new ArrayList<org.geomajas.geometry.Geometry>(); double buffer = request.getBufferDistance(); int quadrantSegments = request.getQuadrantSegments(); for (Geometry clientGeometry : clientGeometries) { result.add(converter.toDto(converter.toInternal(clientGeometry).buffer(buffer, quadrantSegments))); } response.setGeometries(result); }  @Override GeometryBufferRequest getEmptyCommandRequest(); @Override GeometryBufferResponse getEmptyCommandResponse(); @Override void execute(GeometryBufferRequest request, GeometryBufferResponse response);  }
@Test public void bufferTest() throws GeomajasException { GeometryBufferRequest request = new GeometryBufferRequest(); request.setGeometries(geometries); request.setBufferDistance(50); GeometryBufferResponse response = (GeometryBufferResponse) dispatcher.execute( GeometryBufferRequest.COMMAND, request, null, "en"); List<Geometry> buffered = response.getGeometries(); Assert.assertEquals(3, buffered.size()); Assert.assertTrue(buffered.get(0).getGeometries()[0].getCoordinates().length > 4); Assert.assertTrue(buffered.get(1).getGeometries()[0].getCoordinates().length > 2); Assert.assertTrue(buffered.get(2).getGeometries()[0].getCoordinates().length > 1); }
@Test public void bufferZeroTest() throws GeomajasException { GeometryBufferRequest request = new GeometryBufferRequest(); request.setGeometries(geometries); request.setBufferDistance(0); GeometryBufferResponse response = (GeometryBufferResponse) dispatcher.execute( GeometryBufferRequest.COMMAND, request, null, "en"); List<Geometry> buffered = response.getGeometries(); Assert.assertEquals(3, buffered.size()); Assert.assertTrue(buffered.get(0).getGeometries()[0].getCoordinates().length == 4); Assert.assertTrue(buffered.get(1).getGeometryType().equals(Geometry.POLYGON)); Assert.assertTrue(buffered.get(1).getCoordinates() == null); Assert.assertTrue(buffered.get(2).getGeometryType().equals(Geometry.POLYGON)); Assert.assertTrue(buffered.get(2).getCoordinates() == null); }
@Test public void quadrantTest() throws GeomajasException { Geometry point = new Geometry(Geometry.POINT, 3, 0); point.setCoordinates(new Coordinate[]{ new Coordinate(5000, 5000) }); GeometryBufferRequest request = new GeometryBufferRequest(); List<Geometry> g = new ArrayList<Geometry>(); g.add(point); request.setGeometries(g); request.setBufferDistance(900); request.setQuadrantSegments(4); GeometryBufferResponse response = (GeometryBufferResponse) dispatcher.execute( GeometryBufferRequest.COMMAND, request, null, "en"); g = response.getGeometries(); Assert.assertTrue(g.get(0).getGeometries()[0].getCoordinates().length == 17); }