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 } } }
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); }
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)); }
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); }
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; }
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); }
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(); } }
@Override public Shape read(Reader reader) throws IOException, ParseException, InvalidShapeException { return read(WKTReader.readString(reader)); }
public static Geometry readWKT(String inputWKT) throws ParseException { return reader.read(inputWKT); }