Beispiel #1
0
 private Geometry toNullOrGeometry(String wellKnownText) throws ParseException {
   if (wellKnownText == null) {
     return null;
   }
   GeometryFactory fact = new GeometryFactory(pm, 0);
   WKTReader wktRdr = new WKTReader(fact);
   return wktRdr.read(wellKnownText);
 }
Beispiel #2
0
 public void initGeometry() throws ParseException {
   GeometryFactory fact = new GeometryFactory(pm, 0);
   WKTReader wktRdr = new WKTReader(fact);
   if (geom[0] != null) {
     return;
   }
   if (wkta != null) {
     geom[0] = wktRdr.read(wkta);
   }
   if (wktb != null) {
     geom[1] = wktRdr.read(wktb);
   }
 }
  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));
  }
 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);
 }
  public void findClosestPoint(String wktA, String wktB) {
    System.out.println("-------------------------------------");
    try {
      Geometry A = wktRdr.read(wktA);
      Geometry B = wktRdr.read(wktB);
      System.out.println("Geometry A: " + A);
      System.out.println("Geometry B: " + B);
      DistanceOp distOp = new DistanceOp(A, B);

      double distance = distOp.distance();
      System.out.println("Distance = " + distance);

      Coordinate[] closestPt = distOp.nearestPoints();
      LineString closestPtLine = fact.createLineString(closestPt);
      System.out.println(
          "Closest points: " + closestPtLine + " (distance = " + closestPtLine.getLength() + ")");
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }