Esempio n. 1
0
  private static final List<Coord> getRandomCoordinatesInZone(
      int numCoordinates, Geometry zoneGeometry, Random random) {

    /*
     * Get the bounding box of the geometry. The returned geometry is a polygon with the following points:
     * (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).
     */
    Geometry envelope = zoneGeometry.getEnvelope();
    Coordinate[] coords = envelope.getCoordinates();

    double minX = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE;
    double minY = Double.MAX_VALUE;
    double maxY = Double.MIN_VALUE;

    for (Coordinate coord : coords) {
      if (coord.x < minX) minX = coord.x;
      if (coord.x > maxX) maxX = coord.x;
      if (coord.y < minY) minY = coord.y;
      if (coord.y > maxY) maxY = coord.y;
    }

    List<Coord> list = new ArrayList<Coord>();

    // loop until a valid point was found and is returned
    while (list.size() < numCoordinates) {
      double x = minX + random.nextDouble() * (maxX - minX);
      double y = minY + random.nextDouble() * (maxY - minY);

      Point point = geometryFactory.createPoint(new Coordinate(x, y));
      if (zoneGeometry.contains(point))
        list.add(fromWGS84CoordinateTransformation.transform(new Coord(x, y)));
    }
    return list;
  }
Esempio n. 2
0
 @Override
 public Double exec(Tuple input) throws IOException {
   try {
     Object v = input.get(0);
     Geometry geom = geometryParser.parseGeom(v);
     Coordinate[] coords = geom.getEnvelope().getCoordinates();
     return Math.max(coords[0].x, coords[2].x);
   } catch (ExecException ee) {
     throw ee;
   }
 }
Esempio n. 3
0
  private static boolean checkActivityInArea(Geometry area, ActivityImpl activity) {

    boolean inArea = false;
    Coord coord = activity.getCoord();
    double x = coord.getX();
    double y = coord.getY();
    Coordinate coordinate = new Coordinate(x, y);
    GeometryFactory gf = new GeometryFactory();
    Point activityPoint = gf.createPoint(coordinate);
    Geometry envelope = area.getEnvelope();

    if (envelope.covers(activityPoint)) {
      if (area.covers(activityPoint)) {
        inArea = true;
      }
    }

    return inArea;
  }
    public boolean hasNext() {
      //   logger.info("qui");
      logger.finer("HAS NEXT");
      while ((next == null && delegate.hasNext()) || (next == null && added)) {
        //     logger.info("qui nel while");
        if (complete) {
          first = delegate.next();
          intersectedGeometries = null;
        }
        //               logger.info("qui dopo check if (complete)");
        // logger.finer("control HAS NEXT");
        for (Object attribute : first.getAttributes()) {
          if (attribute instanceof Geometry && attribute.equals(first.getDefaultGeometry())) {
            Geometry currentGeom = (Geometry) attribute;

            if (intersectedGeometries == null && !added) {
              intersectedGeometries = filteredCollection(currentGeom, subFeatureCollection);
              iterator = intersectedGeometries.features();
            }
            try {
              while (iterator.hasNext()) {
                added = false;
                SimpleFeature second = iterator.next();
                if (currentGeom
                    .getEnvelope()
                    .intersects(((Geometry) second.getDefaultGeometry()))) {
                  // compute geometry
                  if (intersectionMode == IntersectionMode.INTERSECTION) {
                    attribute = currentGeom.intersection((Geometry) second.getDefaultGeometry());

                    GeometryFilterImpl filter =
                        new GeometryFilterImpl(geomType.getType().getBinding());
                    ((Geometry) attribute).apply(filter);
                    attribute = filter.getGeometry();
                  } else if (intersectionMode == IntersectionMode.FIRST) {
                    attribute = currentGeom;
                  } else if (intersectionMode == IntersectionMode.SECOND) {
                    attribute = (Geometry) second.getDefaultGeometry();
                  }
                  if (((Geometry) attribute).getNumGeometries() > 0) {
                    fb.add(attribute);
                    fb.set("INTERSECTION_ID", id++);
                    // add the non geometric attributes
                    addAttributeValues(first, retainAttributesFst, fb);
                    addAttributeValues(second, retainAttributesSnd, fb);
                    // add the dynamic attributes
                    if (percentagesEnabled) {
                      addPercentages(currentGeom, second);
                    }
                    if (areasEnabled) {
                      addAreas(currentGeom, second);
                    }

                    // build the feature
                    next = fb.buildFeature(iterationIndex.toString());

                    // update iterator status
                    if (iterator.hasNext()) {
                      complete = false;
                      added = true;
                      iterationIndex++;
                      return next != null;
                    }
                    iterationIndex++;
                  }
                }
                complete = false;
              }
              complete = true;
            } finally {
              if (!added) {
                iterator.close();
              }
            }
          }
        }
      }
      return next != null;
    }