TransformGeometryCommand implements CommandHasRequest<TransformGeometryRequest, TransformGeometryResponse> { @Override public void execute(TransformGeometryRequest request, TransformGeometryResponse response) throws Exception { Crs sourceCrs = geoService.getCrs2(request.getSourceCrs()); Crs targetCrs = geoService.getCrs2(request.getTargetCrs()); CrsTransform transform = geoService.getCrsTransform(sourceCrs, targetCrs); if (request.getBounds() != null) { Envelope source = converter.toInternal(request.getBounds()); Envelope target = geoService.transform(source, transform); response.setBounds(converter.toDto(target)); } if (request.getGeometry() != null) { Geometry source = converter.toInternal(request.getGeometry()); Geometry target = geoService.transform(source, transform); response.setGeometry(converter.toDto(target)); } if (request.getGeometryCollection() != null) { for (org.geomajas.geometry.Geometry geometry : request.getGeometryCollection()) { Geometry source = converter.toInternal(geometry); Geometry target = geoService.transform(source, transform); response.getGeometryCollection().add(converter.toDto(target)); } } }  @Override TransformGeometryRequest getEmptyCommandRequest(); @Override TransformGeometryResponse getEmptyCommandResponse(); @Override void execute(TransformGeometryRequest request, TransformGeometryResponse response);  }
@Test public void testTransformBounds() throws Exception { TransformGeometryRequest request = new TransformGeometryRequest(); Bbox origin = new Bbox(10, 30, 10, 10); request.setBounds(origin); request.setSourceCrs(MERCATOR); request.setTargetCrs(LONLAT); TransformGeometryResponse response = (TransformGeometryResponse) dispatcher.execute( TransformGeometryRequest.COMMAND, request, null, "en"); Bbox transformed = response.getBounds(); Assert.assertEquals(8.983152841195215E-5, transformed.getX(), DELTA); Assert.assertEquals(2.6949458522981454E-4, transformed.getY(), DELTA); Assert.assertEquals(1.796630568239043E-4, transformed.getMaxX(), DELTA); Assert.assertEquals(3.593261136397527E-4, transformed.getMaxY(), DELTA); }
@Test public void testTransformGeometry() throws Exception { TransformGeometryRequest request = new TransformGeometryRequest(); WKTReader reader = new WKTReader(); Geometry origin = converterService.toDto(reader.read("POLYGON((10 30, 20 30,20 40,10 40,10 30))")); request.setGeometry(origin); request.setSourceCrs(MERCATOR); request.setTargetCrs(LONLAT); TransformGeometryResponse response = (TransformGeometryResponse) dispatcher.execute( TransformGeometryRequest.COMMAND, request, null, "en"); Geometry transformed = response.getGeometry(); Envelope bounds = converterService.toInternal(transformed).getEnvelopeInternal(); Assert.assertEquals(8.983152841195215E-5, bounds.getMinX(), DELTA); Assert.assertEquals(2.6949458522981454E-4, bounds.getMinY(), DELTA); Assert.assertEquals(1.796630568239043E-4, bounds.getMaxX(), DELTA); Assert.assertEquals(3.593261136397527E-4, bounds.getMaxY(), DELTA); }
@Test public void testTransformGeometryCollection() throws Exception { TransformGeometryRequest request = new TransformGeometryRequest(); WKTReader reader = new WKTReader(); Geometry origin = converterService.toDto(reader.read("POLYGON((10 30, 20 30,20 40,10 40,10 30))")); List<Geometry> geometries = request.getGeometryCollection(); geometries.add(origin); request.setGeometryCollection(geometries); request.setSourceCrs(MERCATOR); request.setTargetCrs(LONLAT); TransformGeometryResponse response = (TransformGeometryResponse) dispatcher.execute( TransformGeometryRequest.COMMAND, request, null, "en"); List<Geometry> transformed = response.getGeometryCollection(); Assert.assertEquals(1, transformed.size()); Envelope bounds = converterService.toInternal(transformed.get(0)).getEnvelopeInternal(); Assert.assertEquals(8.983152841195215E-5, bounds.getMinX(), DELTA); Assert.assertEquals(2.6949458522981454E-4, bounds.getMinY(), DELTA); Assert.assertEquals(1.796630568239043E-4, bounds.getMaxX(), DELTA); Assert.assertEquals(3.593261136397527E-4, bounds.getMaxY(), DELTA); }