@Override public List getProperties(Object object, XSDElementDeclaration element) throws Exception { BBOX box = (BBOX) object; List properties = new ArrayList(); Envelope env = null; try { String srs = box.getSRS(); if (srs != null) { CoordinateReferenceSystem crs = CRS.decode(srs); env = new ReferencedEnvelope( box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), crs); } } catch (Throwable t) { // never mind } if (env == null) { env = new Envelope(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY()); } properties.add(new Object[] {ENVELOPE_PARTICLE, env}); return properties; } }
public Object getProperty(Object object, QName name) throws Exception { BBOX box = (BBOX) object; // <xsd:element ref="ogc:PropertyName"/> if (OGC.PropertyName.equals(name)) { return factory.property(box.getPropertyName()); } // <xsd:element ref="gml:Box"/> if (GML.Box.equals(name) || org.geotools.gml3.GML.Envelope.equals(name)) { try { String srs = box.getSRS(); if (srs != null) { CoordinateReferenceSystem crs = CRS.decode(srs); return new ReferencedEnvelope( box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), crs); } } catch (Throwable t) { // never mind } return new Envelope(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY()); } return null; } }
/** Expands the BBOX in the Filter. */ @SuppressWarnings("deprecation") @Override public Object visit(BBOX filter, Object extraData) { // no need to change the property name Expression propertyName = filter.getExpression1(); /** Using the deprecated methods since they are too useful... */ double minx = filter.getMinX(); double miny = filter.getMinY(); double maxx = filter.getMaxX(); double maxy = filter.getMaxY(); String srs = filter.getSRS(); return getFactory(extraData) .bbox( propertyName, minx - expandMinX, miny - expandMaxX, maxx + expandMinY, maxy + expandMaxY, srs); } }
public Object visit(BBOX filter, Object extraData) { // if no srs is specified we can't transform anyways String srs = filter.getSRS(); if (srs != null && !"".equals(srs.trim())) return super.visit(filter, extraData); if (defaultCrs == null || filter.getBounds() == null || defaultCrs.getCoordinateSystem().getDimension() == filter.getBounds().getDimension()) { return getFactory(extraData) .bbox( filter.getExpression1(), ReferencedEnvelope.create(filter.getBounds(), defaultCrs)); } else { try { SingleCRS horizontalCRS = CRS.getHorizontalCRS(defaultCrs); ReferencedEnvelope bounds = ReferencedEnvelope.create(filter.getBounds(), horizontalCRS); return getFactory(extraData).bbox(filter.getExpression1(), bounds); } catch (Exception e) { throw new RuntimeException("Could not decode srs '" + srs + "'", e); } } }
@Override public Object visit(BBOX filter, Object extraData) { // rename if necessary Expression e1 = filter.getExpression1(); if (e1 instanceof PropertyName) { PropertyName pname = (PropertyName) e1; String name = pname.getPropertyName(); if (name != null && name.equals(source)) { e1 = ff.property(target); } } // duplicate preserving fast bbox filters if (filter instanceof FastBBOX && e1 instanceof PropertyName) { FastBBOX fbox = (FastBBOX) filter; return new FastBBOX((PropertyName) e1, fbox.getEnvelope(), getFactory(extraData)); } else { double minx = filter.getMinX(); double miny = filter.getMinY(); double maxx = filter.getMaxX(); double maxy = filter.getMaxY(); String srs = filter.getSRS(); return getFactory(extraData).bbox(e1, minx, miny, maxx, maxy, srs); } } }
@Test public void testPreserveOriginalSRS() throws NoSuchAuthorityCodeException, FactoryException { String srs = "AUTO:42004,9001,0,33"; CoordinateReferenceSystem crs = CRS.decode(srs); BBOX bbox = ff.bbox(ff.property(""), 0, 1000, 2000, 3000, srs); Geometry geom = bbox.getExpression2().evaluate(null, Geometry.class); assertEquals(crs, geom.getUserData()); assertEquals(srs, bbox.getSRS()); } }
public Object visit(BBOX filter, Object extraData) { Expression propertyName = visit(filter.getExpression1(), extraData); if (!(filter instanceof BBOX3D)) { double minx = filter.getMinX(); double miny = filter.getMinY(); double maxx = filter.getMaxX(); double maxy = filter.getMaxY(); String srs = filter.getSRS(); return getFactory(extraData) .bbox(propertyName, minx, miny, maxx, maxy, srs, filter.getMatchAction()); } return getFactory(extraData).bbox(propertyName, filter.getBounds()); }
public void testParse() throws Exception { FilterMockData.bbox(document, document); BBOX box = (BBOX) parse(); assertEquals("foo", box.getPropertyName()); assertEquals(0, box.getMinX(), 0.0); assertEquals(0, box.getMinY(), 0.0); assertEquals(1, box.getMaxX(), 0.0); assertEquals(1, box.getMaxY(), 0.0); assertEquals("EPSG:4326", box.getSRS()); }
/** The provided target CRS (3857) should override the native one (4326). */ public void testBboxReprojectWithTargetCrsProvided() throws FactoryException { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(ff, ft, CRS.decode("EPSG:3857")); BBOX bbox = ff.bbox(ff.property("geom"), 10, 15, 20, 25, "EPSG:4326"); Filter clone = (Filter) bbox.accept(reprojector, null); assertNotSame(bbox, clone); BBOX clonedBbox = (BBOX) clone; assertEquals(bbox.getPropertyName(), clonedBbox.getPropertyName()); assertEquals(1113194.9079327357, clonedBbox.getMinX(), 0.1); assertEquals(1689200.1396078924, clonedBbox.getMinY(), 0.1); assertEquals(2226389.8158654715, clonedBbox.getMaxX(), 0.1); assertEquals(2875744.6243522423, clonedBbox.getMaxY(), 0.1); assertEquals("EPSG:3857", clonedBbox.getSRS()); }
/** * The provided target CRS (3857) should not override the native one (4326) since the use * property is not a geometry. */ public void testTargetCrsProvidedButNoGeometryProperty() throws FactoryException { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(ff, ft, CRS.decode("EPSG:3857")); BBOX bbox = ff.bbox(ff.property("name"), 10, 15, 20, 25, "EPSG:4326"); BBOX clone = (BBOX) bbox.accept(reprojector, null); assertNotSame(bbox, clone); // check that no reprojection was applied assertEquals(bbox.getPropertyName(), clone.getPropertyName()); assertEquals(10.0, clone.getMinX(), 0.1); assertEquals(15.0, clone.getMinY(), 0.1); assertEquals(20.0, clone.getMaxX(), 0.1); assertEquals(25.0, clone.getMaxY(), 0.1); assertEquals("EPSG:4326", clone.getSRS()); }
public void testBboxReproject() { // see if coordinates gets flipped, urn forces lat/lon interpretation BBOX bbox = ff.bbox(ff.property("geom"), 10, 15, 20, 25, "urn:x-ogc:def:crs:EPSG:6.11.2:4326"); Filter clone = (Filter) bbox.accept(reprojector, null); assertNotSame(bbox, clone); BBOX clonedBbox = (BBOX) clone; assertEquals(bbox.getPropertyName(), clonedBbox.getPropertyName()); assertEquals(15, clonedBbox.getMinX(), 1e-6); assertEquals(10, clonedBbox.getMinY(), 1e-6); assertEquals(25, clonedBbox.getMaxX(), 1e-6); assertEquals(20, clonedBbox.getMaxY(), 1e-6); assertEquals("EPSG:4326", clonedBbox.getSRS()); }
String srs = filter.getSRS(); return getFactory(extraData).bbox(propertyName, minx, miny, maxx, maxy, srs); } else {
public Object visit(BBOX filter, Object arg1) { String propertyName = filter.getPropertyName(); if (propertyName.length() < 1) { // see GetFeatureKvpRequestReader bboxFilter() // propertyName is meant to be empty, and it will get it from the feature // later (if not available, it will use feature's default geometry) // instead of always use the default geometry from the feature type return filter; } Expression name = ff.property(propertyName); final List sourceNames = (List) name.accept(this, null); final List combined = new ArrayList(sourceNames.size()); for (Iterator it = sourceNames.iterator(); it.hasNext();) { Expression sourceName = (Expression) it.next(); Filter unrolled = ff.bbox(sourceName, filter.getMinX(), filter.getMinY(), filter .getMaxX(), filter.getMaxY(), filter.getSRS(), filter.getMatchAction()); combined.add(unrolled); } Filter unrolled = combineOred(combined); return unrolled; }
public Object visit(BBOX filter, Object extraData) { // if no srs is specified we can't transform anyways String srs = filter.getSRS(); if (srs != null && !"".equals(srs.trim())) return super.visit(filter, extraData); try { // grab the original envelope data double minx = filter.getMinX(); double miny = filter.getMinY(); double maxx = filter.getMaxX(); double maxy = filter.getMaxY(); String propertyName = filter.getPropertyName(); String defaultSrs = CRS.toSRS(defaultCrs); return getFactory(extraData).bbox(propertyName, minx, miny, maxx, maxy, defaultSrs); } catch (Exception e) { throw new RuntimeException("Could not decode srs '" + srs + "'", e); } }
public Object visit(BBOX filter, Object extraData) { String propertyName=filter.getPropertyName(); double [] coords= new double[4]; coords[0]=filter.getMinX(); coords[1]=filter.getMinY(); coords[2]=filter.getMaxX(); coords[3]=filter.getMaxY(); String srs=filter.getSRS(); double[] dest=new double[4]; try { mt.transform(coords, 0, dest, 0, 2); } catch (TransformException e) { throw new RuntimeException(e); } return getFactory(extraData).bbox(propertyName, dest[0], dest[1], dest[2], dest[3], srs); }
public Object visit(BBOX filter, Object extraData) { String propertyName=filter.getPropertyName(); double minx=filter.getMinX(); double miny=filter.getMinY(); double maxx=filter.getMaxX(); double maxy=filter.getMaxY(); String srs=filter.getSRS(); return getFactory(extraData).bbox(propertyName, minx, miny, maxx, maxy, srs); }
public Object visit(BBOX filter, Object extraData) { String propertyName=filter.getPropertyName(); double [] coords= new double[4]; coords[0]=filter.getMinX(); coords[1]=filter.getMinY(); coords[2]=filter.getMaxX(); coords[3]=filter.getMaxY(); String srs=filter.getSRS(); double[] dest=new double[4]; try { mt.transform(coords, 0, dest, 0, 2); } catch (TransformException e) { throw new RuntimeException(e); } return getFactory(extraData).bbox(propertyName, dest[0], dest[1], dest[2], dest[3], srs); }
public Object visit(BBOX filter, Object extraData) { Expression propertyName = visit(filter.getExpression1(), extraData); double minx=filter.getMinX(); double miny=filter.getMinY(); double maxx=filter.getMaxX(); double maxy=filter.getMaxY(); String srs=filter.getSRS(); return getFactory(extraData).bbox(propertyName, minx, miny, maxx, maxy, srs); }
@Test public void testReprojectFilterWithTargetCrs() throws FactoryException { BBOX bbox = filterFactory.bbox(filterFactory.property("geom"), 10, 15, 20, 25, "EPSG:4326"); Filter clone = WFSReprojectionUtil.reprojectFilter(bbox, featureType, CRS.decode("EPSG:3857")); assertNotSame(bbox, clone); BBOX clonedBbox = (BBOX) clone; assertEquals(bbox.getPropertyName(), clonedBbox.getPropertyName()); assertEquals(1669792.3618991035, clonedBbox.getMinX(), 0.1); assertEquals(1118889.9748579597, clonedBbox.getMinY(), 0.1); assertEquals(2782987.269831839, clonedBbox.getMaxX(), 0.1); assertEquals(2273030.926987689, clonedBbox.getMaxY(), 0.1); assertEquals("EPSG:3857", clonedBbox.getSRS()); } }