Exemplo n.º 1
0
  public static void createGeom(List<Node> nodes) {
    StringBuilder wkt = new StringBuilder();
    for (Node node : nodes) wkt.append(node.lng + " " + node.lat + ", ");
    wkt.delete(wkt.length() - 2, wkt.length());

    wkt.insert(0, "POLYGON((");
    wkt.append("))");

    WKTReader wktreader = new WKTReader();
    Geometry geom = null;
    try {
      geom = wktreader.read(wkt.toString());
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    Polygon pol = (Polygon) geom;

    if (!pol.isValid()) {
      Geometry repaired = pol.buffer(0.0D);
      log.info("Invalid polygon detected. Is fixed? " + repaired.isValid());
      wkt = new StringBuilder(repaired.toText());
    }

    try {
      System.out.println(pol.contains(wktreader.read("POINT(82 25)")));
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  /**
   * Analyze the feature list, and for those features that can suffer split operation, they'll be
   * split.
   *
   * @return The builder instance.
   * @throws SplitFeatureBuilderFailException if the operation fail
   * @throws CannotSplitException if the split line cannot divide the feature's geometry
   */
  public SplitFeatureBuilder buildSplit()
      throws SplitFeatureBuilderFailException, CannotSplitException {

    try {
      this.splitResultList = new LinkedList<SimpleFeature>();
      boolean existSplit = false;
      for (SimpleFeature feature : this.featureList) {

        Geometry geomToSplit = (Geometry) feature.getDefaultGeometry();
        assert geomToSplit.isValid() : "No Valid Geometry: " + geomToSplit.toText(); // $NON-NLS-1$
        CoordinateReferenceSystem featureCrs =
            feature.getFeatureType().getCoordinateReferenceSystem();
        geomToSplit = GeoToolsUtils.reproject(geomToSplit, featureCrs, this.desiredCRS);

        if (canSplit(geomToSplit)) {
          existSplit = true;
          this.featuresThatSufferedSplit.add(feature);

          List<Geometry> splitGeometriesResult = split(geomToSplit);
          this.splitResultList.addAll(createSplitFeatures(splitGeometriesResult, feature));
        }
      }
      if (!existSplit) {
        throw new CannotSplitException("The split line cannot split any features"); // $NON-NLS-1$
      }
    } catch (OperationNotFoundException e) {
      throw makeFailException(e);
    } catch (TransformException e) {
      throw makeFailException(e);
    }
    return this;
  }
Exemplo n.º 3
0
  private void validate(final Geometry geom, final List<ValidationResult> validationErrors) {

    if (geom.isEmpty()) {
      return;
    }

    if (geom instanceof GeometryCollection) {
      final GeometryCollection gc = (GeometryCollection) geom;
      for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) {
        validate(gc.getGeometryN(numGeom), validationErrors);
      }
    }

    final ValidationResult result = new ValidationResult();
    result.setWkt(geom.toText());
    final List<String> messages = new ArrayList<String>();

    if (!geom.isValid()) {
      messages.add("Error en topología básica");
    }

    if (!geom.isSimple()) {
      messages.add("No es una geometría simple");
    }

    if (repeatedPointTester.hasRepeatedPoint(geom)) {
      messages.add("Se encuentran vértices repetidos");
    }

    if (geom instanceof Polygon) {
      final Polygon polygon = (Polygon) geom;
      if (CGAlgorithms.isCCW(polygon.getExteriorRing().getCoordinates())) {
        messages.add("Error en orientación del polígono");
      } else {

        for (int numRing = 0; numRing < polygon.getNumInteriorRing(); numRing++) {
          if (!CGAlgorithms.isCCW(polygon.getInteriorRingN(numRing).getCoordinates())) {
            messages.add("Error en orientación del polígono en anillos interiores");
            break;
          }
        }
      }

      if (!validateMinPolygonArea(geom)) {
        messages.add("Error en validación mínima de area de un polígono");
      }
    }

    if (!validateMinSegmentLength(geom)) {
      messages.add("Error en validación mínima de longitud de segmento");
    }

    if (!messages.isEmpty()) {
      result.setMessages(messages);
      validationErrors.add(result);
    }
  }