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))); }
@Test public void testGeoPointAsDoubleArray() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; final Geometry geometry = parserUtil.createGeometry(Arrays.asList(new Double[] {lon, lat})); assertTrue(geometry.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
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))); }
@Test public void testGeoPointPatternForFractions() { final double lat = rand.nextDouble() * 2 - 1; final double lon = rand.nextDouble() * 2 - 1; final String value = (lat + "," + lon).replace("0.", "."); final Geometry geom = parserUtil.createGeometry(value); assertTrue(geom.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
@Test public void testParseGeoPointPatternForNegatives() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; final String value = lat + "," + lon; final Geometry geom = parserUtil.createGeometry(value); assertTrue(geom.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
@Test public void testGeoPointAsProperties() { final double lat = rand.nextDouble() * 90 - 90; final double lon = rand.nextDouble() * 180 - 180; properties.put("lat", lat); properties.put("lon", lon); final Geometry geometry = parserUtil.createGeometry(properties); assertTrue(geometry.equals(geometryFactory.createPoint(new Coordinate(lon, lat)))); }
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())); }
@Override public void mouseClicked(final MouseEvent e) { final int button = e.getButton(); if (button == MouseEvent.BUTTON1) { if (feature == null) { setCurrentFeature(helper.grabFeature(e.getX(), e.getY(), false)); } } else if (button == MouseEvent.BUTTON3 && feature != null) { final Geometry oldgeom = (Geometry) FeatureExt.getDefaultGeometryAttributeValue(feature); final Geometry newGeom = dialogDecoration.clipboardPanel.getGeometry(); if (!oldgeom.equals(newGeom)) { helper.sourceModifyFeature(feature, newGeom, false); } reset(); } }
public static void assertEquals(Geometry s1, Geometry s2) { if (s1 instanceof LineString && s2 instanceof LineString) { assertEquals((LineString) s1, (LineString) s2); } else if (s1 instanceof Polygon && s2 instanceof Polygon) { assertEquals((Polygon) s1, (Polygon) s2); } else if (s1 instanceof MultiPoint && s2 instanceof MultiPoint) { assert s1.equals(s2) : "Expected " + s1 + " but found " + s2; } else if (s1 instanceof MultiPolygon && s2 instanceof MultiPolygon) { assertEquals((MultiPolygon) s1, (MultiPolygon) s2); } else { throw new RuntimeException( "equality of shape types not supported [" + s1.getClass().getName() + " and " + s2.getClass().getName() + "]"); } }
/** @return a boolean Literal that is true if geom1 equals geom2. */ @Override protected Literal evaluate( ValueFactory valueFactory, Geometry geom1, Geometry geom2, Value... allArgs) { return valueFactory.createLiteral(geom1.equals(geom2)); }
@Test public void testGeoPointPatternForWholeValues() { final Geometry geom = parserUtil.createGeometry("45,90"); assertTrue(geom.equals(geometryFactory.createPoint(new Coordinate(90, 45)))); }
/** * Returns a boolean value that shows if two geometries are equal or not. * * @param node1 xml element containing gml object(s) * @param node2 xml element containing gml object(s) * @return boolean value * @throws QueryException query exception */ @Deterministic public Bln equals(final ANode node1, final ANode node2) throws QueryException { final Geometry geo1 = checkGeo(node1); final Geometry geo2 = checkGeo(node2); return Bln.get(geo1.equals(geo2)); }