public void testExecuteBuffer() throws Exception { org.geotools.process.Process buffer = factory.create(new NameImpl("JTS", "Buffer")); // try less than the required params Map<String, Object> inputs = new HashMap<String, Object>(); try { buffer.execute(inputs, null); fail("What!!! Should have failed big time!"); } catch (ProcessException e) { // fine } // try out only the required params Geometry geom = new WKTReader().read("POINT(0 0)"); inputs.put("geom", geom); inputs.put("distance", 1d); Map<String, Object> result = buffer.execute(inputs, null); assertEquals(1, result.size()); Geometry buffered = (Geometry) result.get("result"); assertNotNull(buffered); assertTrue(buffered.equals(geom.buffer(1d))); // pass in all params inputs.put("quadrantSegments", 12); inputs.put("capStyle", GeometryFunctions.BufferCapStyle.Square); result = buffer.execute(inputs, null); assertEquals(1, result.size()); buffered = (Geometry) result.get("result"); assertNotNull(buffered); assertTrue(buffered.equals(geom.buffer(1d, 12, BufferParameters.CAP_SQUARE))); }
public void testExecuteUnion() throws Exception { org.geotools.process.Process union = factory.create(new NameImpl("JTS", "union")); // try less than the required params Map<String, Object> inputs = new HashMap<String, Object>(); try { union.execute(inputs, null); fail("What!!! Should have failed big time!"); } catch (ProcessException e) { // fine } // try again with less Geometry geom1 = new WKTReader().read("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))"); Geometry geom2 = new WKTReader().read("POLYGON((0 1, 0 2, 1 2, 1 1, 0 1))"); List<Geometry> geometries = new ArrayList<Geometry>(); geometries.add(geom1); inputs.put("geom", geometries); try { union.execute(inputs, null); fail("What!!! Should have failed big time!"); } catch (ProcessException e) { // fine } // now with just enough geometries.add(geom2); Map<String, Object> result = union.execute(inputs, null); assertEquals(1, result.size()); Geometry united = (Geometry) result.get("result"); assertNotNull(united); assertTrue(united.equals(geom1.union(geom2))); }
public void testExecuteHull() throws Exception { NameImpl hullName = new NameImpl("JTS", "convexHull"); org.geotools.process.Process hull = factory.create(hullName); Map<String, Object> inputs = new HashMap<String, Object>(); Geometry geom = new WKTReader().read("LINESTRING(0 0, 0 1, 1 1)"); inputs.put("geom", geom); Map<String, Object> output = hull.execute(inputs, null); assertEquals(1, output.size()); // there is no output annotation, check there is consistency between what is declared // and what is returned Geometry result = (Geometry) output.get(factory.getResultInfo(hullName, null).keySet().iterator().next()); assertTrue(result.equals(geom.convexHull())); }