/** DWithin filter maps to a Point/Radius distance Spatial search criteria. */
  @Override
  public Object visit(DWithin filter, Object data) {
    logger.debug("ENTERING: DWithin filter");
    if (curNest == null || NestedTypes.AND.equals(curNest)) {
      // The geometric point is wrapped in a <Literal> element, so have to
      // get geometry expression as literal and then evaluate it to get
      // the geometry.
      // Example:
      // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl@dc33f184</ogc:Literal>
      Literal literalWrapper = (Literal) filter.getExpression2();

      // Luckily we know what type the geometry expression should be, so
      // we
      // can cast it
      PointImpl point = (PointImpl) literalWrapper.evaluate(null);
      double[] coords = point.getCentroid().getCoordinate();
      double distance = filter.getDistance();

      logger.debug("point: coords[0] = " + coords[0] + ",   coords[1] = " + coords[1]);
      logger.debug("radius = " + distance);

      this.spatialSearch = new SpatialDistanceFilter(coords[0], coords[1], distance);

      filters.add(filter);
    } else {
      logger.warn(ONLY_AND_MSG);
    }

    logger.debug("EXITING: DWithin filter");

    return super.visit(filter, data);
  }
  private void handleTemporal(BinaryTemporalOperator filter) {

    Literal literalWrapper = (Literal) filter.getExpression2();
    logger.debug("literalWrapper.getValue() = " + literalWrapper.getValue());

    Object literal = literalWrapper.evaluate(null);
    if (literal instanceof Period) {
      Period period = (Period) literal;

      // Extract the start and end dates from the filter
      Date start = period.getBeginning().getPosition().getDate();
      Date end = period.getEnding().getPosition().getDate();

      temporalSearch = new TemporalFilter(start, end);

      filters.add(filter);
    } else if (literal instanceof PeriodDuration) {

      DefaultPeriodDuration duration = (DefaultPeriodDuration) literal;

      // Extract the start and end dates from the filter
      Date end = Calendar.getInstance().getTime();
      Date start = new Date(end.getTime() - duration.getTimeInMillis());

      temporalSearch = new TemporalFilter(start, end);

      filters.add(filter);
    }
  }
예제 #3
0
 Object visitDistanceSpatialOperator(
     DistanceBufferOperator filter,
     PropertyName property,
     Literal geometry,
     boolean swapped,
     Object extraData) {
   try {
     if ((filter instanceof DWithin && !swapped) || (filter instanceof Beyond && swapped)) {
       out.write("db2gse.ST_Distance(");
       property.accept(this, extraData);
       out.write(",");
       geometry.accept(this, extraData);
       out.write(") < ");
       out.write(Double.toString(filter.getDistance()));
       addSelectivity();
     }
     if ((filter instanceof DWithin && swapped) || (filter instanceof Beyond && !swapped)) {
       out.write("db2gse.ST_Distance(");
       property.accept(this, extraData);
       out.write(",");
       geometry.accept(this, extraData);
       out.write(") > ");
       out.write(Double.toString(filter.getDistance()));
       addSelectivity();
     }
     return extraData;
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
 }
  public void testParse() throws Exception {
    FilterMockData.literal(document, document);

    Literal literal = (Literal) parse();
    assertNotNull(literal);
    assertEquals("foo", literal.getValue());
  }
 public Object visit(Literal expression, Object notUsed) {
   if (expression.getValue() == null) {
     postStack.push(expression);
   }
   preStack.push(expression);
   return null;
 }
  /** Contains filter maps to a Polygon or BBox Spatial search criteria. */
  @Override
  public Object visit(Contains filter, Object data) {
    logger.debug("ENTERING: Contains filter");
    if (curNest == null || NestedTypes.AND.equals(curNest)) {
      // The geometric point is wrapped in a <Literal> element, so have to
      // get geometry expression as literal and then evaluate it to get
      // the geometry.
      // Example:
      // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
      Literal literalWrapper = (Literal) filter.getExpression2();
      Object geometryExpression = literalWrapper.getValue();

      StringBuffer geometryWkt = new StringBuffer();

      if (geometryExpression instanceof SurfaceImpl) {
        SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);

        Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();

        geometryWkt.append("POLYGON((");
        for (int i = 0; i < coords.length; i++) {
          geometryWkt.append(coords[i].x);
          geometryWkt.append(" ");
          geometryWkt.append(coords[i].y);

          if (i != (coords.length - 1)) {
            geometryWkt.append(",");
          }
        }
        geometryWkt.append("))");
        this.spatialSearch = new SpatialFilter(geometryWkt.toString());

        logger.debug("geometryWkt = [" + geometryWkt.toString() + "]");

        filters.add(filter);

      } else {
        logger.warn("Only POLYGON geometry WKT for Contains filter is supported");
      }
    } else {
      logger.warn(ONLY_AND_MSG);
    }

    logger.debug("EXITING: Contains filter");

    return super.visit(filter, data);
  }
예제 #7
0
 /**
  * Construct the appropriate geometry type from the WKT representation of a literal expression
  *
  * @param expression the expression turn into a geometry constructor.
  * @throws IOException Passes back exception if generated by this.out.write()
  */
 public void visitLiteralGeometry(Literal expression) throws IOException {
   String wktRepresentation = wktWriter.write((Geometry) expression.getValue());
   int spacePos = wktRepresentation.indexOf(" ");
   String geomType = wktRepresentation.substring(0, spacePos);
   this.out.write("db2gse.ST_" + geomType + "('" + wktRepresentation + "', " + getSRID() + ")");
 }
예제 #8
0
  /**
   * Implementation of getProperty for {@link BinarySpatialOpTypeBinding} and {@link
   * DistanceBufferTypeBinding}
   *
   * @param e1 First expression
   * @param e2 Second expression
   * @param name name of property
   * @return the object for the property, or null
   */
  static Object property(Expression e1, Expression e2, QName name) {
    if (OGC.PropertyName.equals(name)) {
      if (e1 instanceof PropertyName) {
        return e1;
      } else if (e2 instanceof PropertyName) {
        return e2;
      }
    }

    if (new QName(GML.NAMESPACE, "_Geometry").equals(name)) {
      if (e1 instanceof Literal) {
        Literal literal = (Literal) e1;

        if (literal.getValue() instanceof Geometry) {
          return literal.getValue();
        }
      } else if (e2 instanceof Literal) {
        Literal literal = (Literal) e2;

        if (literal.getValue() instanceof Geometry) {
          return literal.getValue();
        }
      }
    }

    if (new QName(GML.NAMESPACE, "Box").equals(name) /*filter 1.0*/
        || new QName(GML.NAMESPACE, "Envelope").equals(name) /*filter 1.1*/) {
      if (e1 instanceof Literal) {
        Literal literal = (Literal) e1;

        if (literal.getValue() instanceof Envelope) {
          return literal.getValue();
        }
      } else if (e2 instanceof Literal) {
        Literal literal = (Literal) e2;

        if (literal.getValue() instanceof Envelope) {
          return literal.getValue();
        }
      }
    }

    return null;
  }