@Test public void testDisjointFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2)); Disjoint f = ff.disjoint(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.13"); }
@Test public void testDWithinFilter() throws Exception { init(); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2)); DWithin f = ff.dwithin(ff.property("geo"), ff.literal(ls), 3, SI.METRE.getSymbol()); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.01"); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.10"); }
private static Points getAsPoints( CoordinateSequence seq, ICRS crs, boolean swapAxis ) { int dim = seq.getDimension(); double[] coordinates = new double[ seq.size() * dim ]; int idx = 0; for(int i = 0; i < seq.size(); i++) { for(int j = 0; j < dim; j++) { if(swapAxis) { if(j == 0) { coordinates[idx++] = seq.getOrdinate(i, 1); } else if( j == 1) { coordinates[idx++] = seq.getOrdinate(i, 0); } else { coordinates[idx++] = seq.getOrdinate(i, j); } } else { coordinates[idx++] = seq.getOrdinate(i, j); } } } PackedCoordinateSequenceFactory factory = new PackedCoordinateSequenceFactory(); seq = factory.create(coordinates, dim); return new JTSPoints( crs, seq ); }
protected Geometry getGeometry(final String wkt) { Geometry geom = null; final GeometryFactory factory = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); final WKTReader reader = new WKTReader(factory); try { geom = reader.read(wkt); } catch (ParseException e) { LOG.error(INVALID_WKT_MESSAGE + e.getMessage()); throw new IllegalArgumentException(INVALID_WKT_MESSAGE, e); } return geom; }
private Geometry getGeometry(final String wkt) { Geometry geom = null; final GeometryFactory factory = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); final WKTReader reader = new WKTReader(factory); try { geom = reader.read(wkt); } catch (ParseException e) { LOG.error("Invalid WKT" + e.getMessage()); throw new IllegalArgumentException("Invalid WKT", e); } return geom; }
private Geometry getGeometry(final String wkt) { Geometry geom = null; final GeometryFactory factory = new GeometryFactory( PackedCoordinateSequenceFactory.DOUBLE_FACTORY); final WKTReader reader = new WKTReader(factory); try { geom = reader.read(wkt); } catch (ParseException e) { LOG.error(INVALID_WKT_MESSAGE + e.getMessage()); throw new IllegalArgumentException(INVALID_WKT_MESSAGE, e); } return geom; }
@Test public void testWithinPolygonFilter() throws Exception { init(); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { -180, -90, 180, -90, 180, 90, -180, 90, -180, -90 }, 2)); Within f = ff.within(ff.property("geo"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(11, features.size()); }
@Test public void testCrossesFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 2, 2 }, 2)); Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
@Test public void testNotCrossesFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2)); Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(0, features.size()); }
@Test public void testEqualFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { 3, 2, 6, 2, 6, 7, 3, 7, 3, 2 }, 2)); Equals f = ff.equal(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.13"); }
@Test public void testTouchesFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 1, 1 }, 2)); Touches f = ff.touches(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
@Test public void testWithinFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { 0, 0, 0, 6, 6, 6, 6, 0, 0, 0 }, 2)); Within f = ff.within(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
@Test public void testOverlapsFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create( new double[] { 5.5, 6, 7, 6, 7, 7, 5.5, 7, 5.5, 6 }, 2)); Overlaps f = ff.overlaps(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.13"); }
@Test public void testIntersectsFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { 6, 6, 7, 6, 7, 7, 6, 7, 6, 6 }, 2)); Intersects f = ff.intersects(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.13"); }
@Test public void testContainsFilter() throws Exception { init("not-active","geo3"); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Polygon ls = gf.createPolygon(sf.create(new double[] { 2, 2, 3, 2, 3, 3, 2, 3, 2, 2 }, 2)); Contains f = ff.contains(ff.property("geo3"), ff.literal(ls)); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
@Test public void testBeyondFilter() throws Exception { init(); FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2)); Beyond f = ff.beyond(ff.property("geo"), ff.literal(ls), 1, SI.METRE.getSymbol()); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(9, features.size()); }
public void testMultiPointCS() { GeometryFactory gf = new GeometryFactory(new PackedCoordinateSequenceFactory()); CoordinateSequence mpSeq = gf.getCoordinateSequenceFactory().create(1, 4); mpSeq.setOrdinate(0, 0, 50); mpSeq.setOrdinate(0, 1, -2); mpSeq.setOrdinate(0, 2, 10); mpSeq.setOrdinate(0, 3, 20); MultiPoint mp = gf.createMultiPoint(mpSeq); CoordinateSequence pSeq = ((Point)mp.getGeometryN(0)).getCoordinateSequence(); assertEquals(4, pSeq.getDimension()); for (int i = 0; i < 4; i++) assertEquals(mpSeq.getOrdinate(0, i), pSeq.getOrdinate(0, i)); }
public void testCopyToLargerDim() throws Exception { PackedCoordinateSequenceFactory csFactory = new PackedCoordinateSequenceFactory(); CoordinateSequence cs2D = createTestSequence(csFactory, 10, 2); CoordinateSequence cs3D = csFactory.create(10, 3); CoordinateSequences.copy(cs2D, 0, cs3D, 0, cs3D.size()); assertTrue(CoordinateSequences.isEqual(cs2D, cs3D)); }
public void testCopyToSmallerDim() throws Exception { PackedCoordinateSequenceFactory csFactory = new PackedCoordinateSequenceFactory(); CoordinateSequence cs3D = createTestSequence(csFactory, 10, 3); CoordinateSequence cs2D = csFactory.create(10, 2); CoordinateSequences.copy(cs3D, 0, cs2D, 0, cs2D.size()); assertTrue(CoordinateSequences.isEqual(cs2D, cs3D)); }
private void runWKBTestPackedCoordinate(String wkt) throws IOException, ParseException { GeometryFactory geomFactory = new GeometryFactory( new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.DOUBLE, 2)); WKTReader rdr = new WKTReader(geomFactory); Geometry g = rdr.read(wkt); // Since we are using a PCS of dim=2, only check 2-dimensional storage runWKBTest(g, 2, true); runWKBTest(g, 2, false); }
@Override public WFSDataStore createDataStore(Map<String, Serializable> params, HTTPClient http) throws IOException { final WFSConfig config = WFSConfig.fromParams(params); String user = config.getUser(); String password = config.getPassword(); if (((user == null) && (password != null)) || ((config.getPassword() == null) && (config.getUser() != null))) { throw new IOException("Cannot define only one of USERNAME or PASSWORD, must define both or neither"); } final URL capabilitiesURL = (URL) WFSDataStoreFactory.URL.lookUp(params); http.setUser(config.getUser()); http.setPassword(config.getPassword()); int timeoutMillis = config.getTimeoutMillis(); http.setConnectTimeout(timeoutMillis / 1000); // WFSClient performs version negotiation and selects the correct strategy WFSClient wfsClient; try { wfsClient = new WFSClient(capabilitiesURL, http, new WfsConfigAxisOrder(config)); } catch (ServiceException e) { throw new IOException(e); } WFSDataStore dataStore = new WFSDataStore(wfsClient); // factories dataStore.setFilterFactory(CommonFactoryFinder.getFilterFactory(null)); dataStore.setGeometryFactory(new GeometryFactory(PackedCoordinateSequenceFactory.DOUBLE_FACTORY)); dataStore.setFeatureTypeFactory(new FeatureTypeFactoryImpl()); dataStore.setFeatureFactory(CommonFactoryFinder.getFeatureFactory(null)); dataStore.setNamespaceURI(config.getNamespaceOverride()); return dataStore; }
public Geometry toJts() { double[] coords = new double[nodes.size() * 2]; int i = 0; for (OsmNode n : nodes) { coords[i++] = n.lon; coords[i++] = n.lat; } CoordinateSequence c = PackedCoordinateSequenceFactory.DOUBLE_FACTORY.create(coords, 2); return new LineString(c, null); }