Example #1
0
 /**
  * Returns the nth geometry of a geometry collection, or the geometry if the input is not a
  * collection.
  *
  * @param node xml element containing gml object(s)
  * @param number integer number as the index of nth geometry
  * @return geometry as a gml element
  * @throws QueryException query exception
  */
 @Deterministic
 public ANode geometryN(final ANode node, final Int number) throws QueryException {
   final Geometry geo = checkGeo(node);
   final long n = number.itr();
   if (n < 1 || n > geo.getNumGeometries()) throw GeoErrors.outOfRangeIdx(number);
   return gmlWriter(geo.getGeometryN((int) n - 1));
 }
Example #2
0
 /**
  * Returns a boolean value that shows if whether relationships between the boundaries, interiors
  * and exteriors of two geometries match the pattern specified in intersection-matrix-pattern.
  *
  * @param node1 xml element containing gml object(s)
  * @param node2 xml element containing gml object(s)
  * @param intersectionMatrix intersection matrix for two geometries
  * @return boolean value
  * @throws QueryException query exception
  */
 @Deterministic
 public Bln relate(final ANode node1, final ANode node2, final Str intersectionMatrix)
     throws QueryException {
   final Geometry geo1 = checkGeo(node1);
   final Geometry geo2 = checkGeo(node2);
   return Bln.get(geo1.relate(geo2, intersectionMatrix.toJava()));
 }
Example #3
0
  /**
   * Returns the z-coordinate value for point.
   *
   * @param node xml element containing gml object(s)
   * @return z double value
   * @throws QueryException query exception
   */
  @Deterministic
  public Dbl z(final ANode node) throws QueryException {
    final Geometry geo = geo(node, Q_GML_POINT);
    if (geo == null && checkGeo(node) != null)
      throw GeoErrors.geoType(node.qname().local(), "Line");

    return Dbl.get(geo.getCoordinate().z);
  }
Example #4
0
  /**
   * Returns the nth point of a line.
   *
   * @param node xml element containing gml object(s)
   * @param number index of i-th point
   * @return n-th point as a gml element
   * @throws QueryException query exception
   */
  @Deterministic
  public ANode pointN(final ANode node, final Int number) throws QueryException {
    final Geometry geo = geo(node, Q_GML_LINEARRING, Q_GML_LINESTRING);
    if (geo == null && checkGeo(node) != null)
      throw GeoErrors.geoType(node.qname().local(), "Line");

    final int max = geo.getNumPoints();
    final long n = number.itr();
    if (n < 1 || n > max) throw GeoErrors.outOfRangeIdx(number);

    return gmlWriter(((LineString) geo).getPointN((int) n - 1));
  }
  public void run() throws ParseException {
    GeometryFactory fact = new GeometryFactory();
    WKTReader wktRdr = new WKTReader(fact);

    String wktA = "POLYGON((40 100, 40 20, 120 20, 120 100, 40 100))";
    String wktB = "LINESTRING(20 80, 80 60, 100 140)";
    Geometry A = wktRdr.read(wktA);
    Geometry B = wktRdr.read(wktB);
    Geometry C = A.intersection(B);
    System.out.println("A = " + A);
    System.out.println("B = " + B);
    System.out.println("A intersection B = " + C);
    System.out.println("A relate C = " + A.relate(B));
  }
Example #6
0
 private String convertToWKT(Geometry g, boolean isFormatted) {
   if (g == null) return "";
   if (!isFormatted) return g.toString();
   WKTWriter writer = new WKTWriter();
   writer.setFormatted(isFormatted);
   writer.setMaxCoordinatesPerLine(5);
   return writer.write(g);
 }
  public Geometry buffer(Geometry g, double distance) {
    PrecisionModel precisionModel = workingPrecisionModel;
    if (precisionModel == null) precisionModel = g.getPrecisionModel();

    // factory must be the same as the one used by the input
    geomFact = g.getFactory();

    OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, bufParams);

    OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

    List bufferSegStrList = curveSetBuilder.getCurves();

    // short-circuit test
    if (bufferSegStrList.size() <= 0) {
      return createEmptyResultGeometry();
    }

    // BufferDebug.runCount++;
    // String filename = "run" + BufferDebug.runCount + "_curves";
    // System.out.println("saving " + filename);
    // BufferDebug.saveEdges(bufferEdgeList, filename);
    // DEBUGGING ONLY
    // WKTWriter wktWriter = new WKTWriter();
    // Debug.println("Rings: " + wktWriter.write(convertSegStrings(bufferSegStrList.iterator())));
    // wktWriter.setMaxCoordinatesPerLine(10);
    // System.out.println(wktWriter.writeFormatted(convertSegStrings(bufferSegStrList.iterator())));

    computeNodedEdges(bufferSegStrList, precisionModel);
    graph = new PlanarGraph(new OverlayNodeFactory());
    graph.addEdges(edgeList.getEdges());

    List subgraphList = createSubgraphs(graph);
    PolygonBuilder polyBuilder = new PolygonBuilder(geomFact);
    buildSubgraphs(subgraphList, polyBuilder);
    List resultPolyList = polyBuilder.getPolygons();

    // just in case...
    if (resultPolyList.size() <= 0) {
      return createEmptyResultGeometry();
    }

    Geometry resultGeom = geomFact.buildGeometry(resultPolyList);
    return resultGeom;
  }
Example #8
0
 void assertEqualsExact(Geometry g1, Geometry g2, String msg) {
   Geometry g1Clone = (Geometry) g1.clone();
   Geometry g2Clone = (Geometry) g2.clone();
   g1Clone.normalize();
   g2Clone.normalize();
   assertTrue(g1Clone.equalsExact(g2Clone), msg);
 }
 void checkTransformation(String geomStr)
     throws IOException, ParseException, NoninvertibleTransformationException {
   Geometry geom = rdr.read(geomStr);
   AffineTransformation trans = AffineTransformation.rotationInstance(Math.PI / 2);
   AffineTransformation inv = trans.getInverse();
   Geometry transGeom = (Geometry) geom.clone();
   transGeom.apply(trans);
   // System.out.println(transGeom);
   transGeom.apply(inv);
   // check if transformed geometry is equal to original
   boolean isEqual = geom.equalsExact(transGeom, 0.0005);
   assertTrue(isEqual);
 }
Example #10
0
 /**
  * Returns a geometric object that represents the Point set symmetric difference of two
  * geometries.
  *
  * @param node1 xml element containing gml object(s)
  * @param node2 xml element containing gml object(s)
  * @return symmetric difference geometry as a gml element
  * @throws QueryException query exception
  */
 @Deterministic
 public ANode symDifference(final ANode node1, final ANode node2) throws QueryException {
   final Geometry geo1 = checkGeo(node1);
   final Geometry geo2 = checkGeo(node2);
   return gmlWriter(geo1.symDifference(geo2));
 }
Example #11
0
 /**
  * Returns a geometric object representing the Point set intersection of two geometries.
  *
  * @param node1 xml element containing gml object(s)
  * @param node2 xml element containing gml object(s)
  * @return intersection geometry as a gml element
  * @throws QueryException query exception
  */
 @Deterministic
 public ANode intersection(final ANode node1, final ANode node2) throws QueryException {
   final Geometry geo1 = checkGeo(node1);
   final Geometry geo2 = checkGeo(node2);
   return gmlWriter(geo1.intersection(geo2));
 }
Example #12
0
 /**
  * Returns the shortest distance in the units of the spatial reference system of geometry, between
  * the geometries. The distance is the distance between a point on each of the geometries.
  *
  * @param node1 xml element containing gml object(s)
  * @param node2 xml element containing gml object(s)
  * @return distance double value
  * @throws QueryException query exception
  */
 @Deterministic
 public Dbl distance(final ANode node1, final ANode node2) throws QueryException {
   final Geometry geo1 = checkGeo(node1);
   final Geometry geo2 = checkGeo(node2);
   return Dbl.get(geo1.distance(geo2));
 }
Example #13
0
 /**
  * Returns a boolean value that shows if this geometry overlaps the specified geometry.
  *
  * @param node1 xml element containing gml object(s)
  * @param node2 xml element containing gml object(s)
  * @return boolean value
  * @throws QueryException query exception
  */
 @Deterministic
 public Bln overlaps(final ANode node1, final ANode node2) throws QueryException {
   final Geometry geo1 = checkGeo(node1);
   final Geometry geo2 = checkGeo(node2);
   return Bln.get(geo1.overlaps(geo2));
 }
Example #14
0
 IntersectionMatrix relate(Geometry a, Geometry b) {
   return a.relate(b);
 }
Example #15
0
 public void runTest() throws ParseException {
   failed = false;
   isRun = true;
   initGeometry();
   if (expectedIM != null) {
     IntersectionMatrix im = null;
     if (geom[0] != null && geom[1] != null) {
       im = relate(geom[0], geom[1]);
     }
     if (im != null) {
       String msg = " expected " + expectedIM + ", found " + im.toString();
       assertTrue(im.matches(expectedIM), msg);
     }
   }
   if (expectedBoundary != null) {
     Geometry result = geom[0].getBoundary();
     assertEqualsExact(
         expectedBoundary,
         result,
         " expected boundary " + expectedBoundary.toText() + " , found " + result.toText());
   }
   if (expectedConvexHull != null) {
     Geometry result = geom[0].convexHull();
     assertEqualsExact(
         expectedConvexHull,
         result,
         " expected convex hull " + expectedConvexHull.toText() + " , found " + result.toText());
   }
   if (expectedIntersection != null) {
     Geometry result = geom[0].intersection(geom[1]);
     assertEqualsExact(
         expectedIntersection,
         result,
         " expected intersection "
             + expectedIntersection.toText()
             + " , found "
             + result.toText());
   }
   if (expectedUnion != null) {
     Geometry result = geom[0].union(geom[1]);
     assertEqualsExact(
         expectedUnion,
         result,
         " expected union " + expectedUnion.toText() + " , found " + result.toText());
   }
   if (expectedDifference != null) {
     Geometry result = geom[0].difference(geom[1]);
     assertEqualsExact(
         expectedDifference,
         result,
         " expected difference " + expectedDifference.toText() + " , found " + result.toText());
   }
   if (expectedSymDifference != null) {
     Geometry result = geom[0].symDifference(geom[1]);
     assertEqualsExact(
         expectedSymDifference,
         result,
         " expected sym difference "
             + expectedSymDifference.toText()
             + " , found "
             + result.toText());
   }
 }