Ejemplo n.º 1
0
  public void testParseVsInvalidExceptions(WKTReader reader) throws Exception {
    String txt = null;
    try {
      txt = "garbage";
      reader.read(txt);
      fail("should throw invalid exception");
    } catch (ParseException ex) {
      // expected
    }

    try {
      txt = "POINT(-1000 1000)";
      reader.read(txt);
      fail("should throw invalid shape");
    } catch (InvalidShapeException ex) {
      // expected
    }

    if (reader instanceof JtsWKTReader) {
      try {
        txt = readFirstLineFromRsrc("/fiji.wkt.txt");
        reader.read(txt);
        fail("should throw invalid exception");
      } catch (InvalidShapeException ex) {
        // expected
      }
    }
  }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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));
  }
Ejemplo n.º 5
0
 private void readGoodCheckCoordinate(String wkt, double x, double y)
     throws IOException, ParseException {
   Geometry g = rdr.read(wkt);
   Coordinate pt = g.getCoordinate();
   assertEquals(pt.x, x, 0.0001);
   assertEquals(pt.y, y, 0.0001);
 }
Ejemplo n.º 6
0
 public static List readWKT(String[] inputWKT) throws ParseException {
   ArrayList geometries = new ArrayList();
   for (int i = 0; i < inputWKT.length; i++) {
     geometries.add(reader.read(inputWKT[i]));
   }
   return geometries;
 }
Ejemplo n.º 7
0
 private void readBad(String wkt) throws IOException {
   boolean threwParseEx = false;
   try {
     Geometry g = rdr.read(wkt);
   } catch (ParseException ex) {
     System.out.println(ex.getMessage());
     threwParseEx = true;
   }
   assertTrue(threwParseEx);
 }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
  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();
    }
  }
Ejemplo n.º 10
0
 @Override
 public Shape read(Reader reader) throws IOException, ParseException, InvalidShapeException {
   return read(WKTReader.readString(reader));
 }
Ejemplo n.º 11
0
 public static Geometry readWKT(String inputWKT) throws ParseException {
   return reader.read(inputWKT);
 }