@Override
  public void mouseMoved(final MouseEvent e) {
    if (coords.size() > 2) {
      if (justCreated) {
        coords.remove(coords.size() - 1);
        coords.remove(coords.size() - 1);
        coords.add(helper.toCoord(e.getX(), e.getY()));
        coords.add(helper.toCoord(e.getX(), e.getY()));
      } else {
        coords.remove(coords.size() - 1);
        coords.add(helper.toCoord(e.getX(), e.getY()));
      }

      erase = EditionHelper.createPolygon(coords);
      final Geometry line = EditionHelper.createLinearRing(coords);
      geometry =
          (multipolygon) ? EditionHelper.createMultiPolygon(subGeometries) : subGeometries.get(0);
      try {
        geometry = geometry.difference(erase);
      } catch (TopologyException ex) {
        LOGGER.log(Level.INFO, ex.getLocalizedMessage());
      }
      decoration.setGeometries(UnmodifiableArrayList.wrap(new Geometry[] {geometry, line}));
      return;
    }
    super.mouseMoved(e);
  }
  @Override
  public void mouseClicked(final MouseEvent e) {

    final int button = e.getButton();

    if (button == MouseEvent.BUTTON1) {
      if (geometry == null) {
        setCurrentFeature(helper.grabFeature(e.getX(), e.getY(), false));
      } else {
        if (justCreated) {
          justCreated = false;
          // we must modify the second point since two point where added at the start
          coords.remove(2);
          coords.remove(1);
          coords.add(helper.toCoord(e.getX(), e.getY()));
          coords.add(helper.toCoord(e.getX(), e.getY()));

        } else if (coords.isEmpty()) {
          justCreated = true;
          // this is the first point of the geometry we create
          // add 3 points that will be used when moving the mouse around
          coords.add(helper.toCoord(e.getX(), e.getY()));
          coords.add(helper.toCoord(e.getX(), e.getY()));
          coords.add(helper.toCoord(e.getX(), e.getY()));
        } else {
          justCreated = false;
          coords.add(helper.toCoord(e.getX(), e.getY()));
        }

        erase = EditionHelper.createPolygon(coords);
        final Geometry line = EditionHelper.createLinearRing(coords);
        geometry =
            (multipolygon) ? EditionHelper.createMultiPolygon(subGeometries) : subGeometries.get(0);
        try {
          geometry = geometry.difference(erase);
        } catch (TopologyException ex) {
          LOGGER.log(Level.INFO, ex.getLocalizedMessage());
        }
        decoration.setGeometries(UnmodifiableArrayList.wrap(new Geometry[] {geometry, line}));
      }
    } else if (button == MouseEvent.BUTTON3 && feature != null) {
      // finish editing the feature
      helper.sourceModifyFeature(feature, geometry, true);
      reset();
    }
  }
 private boolean evaluateFeature(SimpleFeature feature) {
   try {
     return getFilter().evaluate(feature);
   } catch (TopologyException e) {
     if (!warned) {
       warned = true;
       Log.warning(
           Geonet.SPATIAL, e.getMessage() + " errors are occuring with filter: " + getFilter());
     }
     if (Log.isDebugEnabled(Geonet.SPATIAL))
       Log.debug(
           Geonet.SPATIAL,
           e.getMessage()
               + ": occurred during a search: "
               + getFilter()
               + " on feature: "
               + feature.getDefaultGeometry());
     return false;
   }
 }
예제 #4
0
  /**
   * Set the bbox for this expression
   *
   * @param env The envelope to set as the bounds.
   * @throws IllegalFilterException If the box can not be created.
   * @task HACK: currently sets the SRID to null, which can cause problems with JTS when it comes to
   *     doing spatial tests
   */
  public final void setBounds(Envelope env) throws IllegalFilterException {
    Coordinate[] coords = new Coordinate[5];
    coords[0] = new Coordinate(env.getMinX(), env.getMinY());
    coords[1] = new Coordinate(env.getMinX(), env.getMaxY());
    coords[2] = new Coordinate(env.getMaxX(), env.getMaxY());
    coords[3] = new Coordinate(env.getMaxX(), env.getMinY());
    coords[4] = new Coordinate(env.getMinX(), env.getMinY());

    LinearRing ring = null;

    try {
      ring = gfac.createLinearRing(coords);
    } catch (TopologyException tex) {
      throw new IllegalFilterException(tex.toString());
    }

    Polygon polygon = gfac.createPolygon(ring, null);
    if (env instanceof ReferencedEnvelope) {
      ReferencedEnvelope refEnv = (ReferencedEnvelope) env;
      polygon.setUserData(refEnv.getCoordinateReferenceSystem());
    }
    super.setValue(polygon);
  }