Refine search
public static void main(String[] args) throws Exception { WKTReader rdr = new WKTReader(); Geometry[] geom = new Geometry[3]; geom[0] = rdr.read("POLYGON (( 100 180, 100 260, 180 260, 180 180, 100 180 ))"); geom[1] = rdr.read("POLYGON (( 80 140, 80 200, 200 200, 200 140, 80 140 ))"); geom[2] = rdr.read("POLYGON (( 160 160, 160 240, 240 240, 240 160, 160 160 ))"); unionUsingBuffer(geom); }
public void intersection(String wktA, String wktB, PrecisionModel pm) throws ParseException { System.out.println("Running example using Precision Model = " + pm); GeometryFactory fact = new GeometryFactory(pm); WKTReader wktRdr = new WKTReader(fact); Geometry A = wktRdr.read(wktA); Geometry B = wktRdr.read(wktB); Geometry C = A.intersection(B); System.out.println("A intersection B = " + C); }
public void difference(String wktA, String wktB, PrecisionModel pm) throws ParseException { System.out.println("-------------------------------------------"); System.out.println("Running example using Precision Model = " + pm); GeometryFactory fact = new GeometryFactory(pm); WKTReader wktRdr = new WKTReader(fact); Geometry A = wktRdr.read(wktA); Geometry B = wktRdr.read(wktB); Geometry C = A.difference(B); System.out.println("A intersection B = " + C); } }
public static void main(String[] args) throws Exception { WKTReader rdr = new WKTReader(); LineString line1 = (LineString) (rdr.read("LINESTRING (0 0, 10 10, 20 20)")); showSelfIntersections(line1); LineString line2 = (LineString) (rdr.read("LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60)")); showSelfIntersections(line2); }
void run() throws Exception { WKTReader rdr = new WKTReader(); Collection lines = new ArrayList(); lines.add(rdr.read("LINESTRING (0 0 , 10 10)")); // isolated edge lines.add(rdr.read("LINESTRING (185 221, 100 100)")); //dangling edge lines.add(rdr.read("LINESTRING (185 221, 88 275, 180 316)")); lines.add(rdr.read("LINESTRING (185 221, 292 281, 180 316)")); lines.add(rdr.read("LINESTRING (189 98, 83 187, 185 221)")); lines.add(rdr.read("LINESTRING (189 98, 325 168, 185 221)")); Polygonizer polygonizer = new Polygonizer(); polygonizer.add(lines); Collection polys = polygonizer.getPolygons(); System.out.println("Polygons formed (" + polys.size() + "):"); System.out.println(polys); }
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)); }
public static void main(String[] args) throws Exception { // read a geometry from a WKT string (using the default geometry factory) Geometry g1 = new WKTReader().read("LINESTRING (0 0, 10 10, 20 20)"); System.out.println("Geometry 1: " + g1); // create a geometry by specifying the coordinates directly Coordinate[] coordinates = new Coordinate[]{new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(20, 20)}; // use the default factory, which gives full double-precision Geometry g2 = new GeometryFactory().createLineString(coordinates); System.out.println("Geometry 2: " + g2); // compute the intersection of the two geometries Geometry g3 = g1.intersection(g2); System.out.println("G1 intersection G2: " + g3); } }
@Override public Point fromString(Class targetClass, String s) { if (s == null) return null; WKTReader reader = new WKTReader(); try { return new Point((com.vividsolutions.jts.geom.Point) reader.read(s)); } catch (ParseException e) { log.error("Parse exception, Caused by {}.", e); throw new PropertyAccessException(e); } }
/** * * @param geomAsWkt WKT representation of a geometry * * @return the JTS representation of the geometry * * @throws ParseException exception while parsing the WKT */ public static Geometry fromWKT(String geomAsWkt) throws ParseException { WKTReader wktReader = new WKTReader(); //TODO: consider use of GeometryFactory return wktReader.read(geomAsWkt); }
public static void main(String[] args) throws Exception { WKTReader rdr = new WKTReader(); Geometry[] geom = new Geometry[3]; geom[0] = rdr.read("POLYGON (( 100 180, 100 260, 180 260, 180 180, 100 180 ))"); geom[1] = rdr.read("POLYGON (( 80 140, 80 200, 200 200, 200 140, 80 140 ))"); geom[2] = rdr.read("POLYGON (( 160 160, 160 240, 240 240, 240 160, 160 160 ))"); unionUsingBuffer(geom); }
public void intersection(String wktA, String wktB, PrecisionModel pm) throws ParseException { System.out.println("Running example using Precision Model = " + pm); GeometryFactory fact = new GeometryFactory(pm); WKTReader wktRdr = new WKTReader(fact); Geometry A = wktRdr.read(wktA); Geometry B = wktRdr.read(wktB); Geometry C = A.intersection(B); System.out.println("A intersection B = " + C); }
public static void main(String[] args) throws Exception { WKTReader rdr = new WKTReader(); LineString line1 = (LineString) (rdr.read("LINESTRING (0 0, 10 10, 20 20)")); showSelfIntersections(line1); LineString line2 = (LineString) (rdr.read("LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60)")); showSelfIntersections(line2); }
/** * Translates between a WKT representation of a geometry and a JTS {@link Geometry} * @param wellKnownText the WKT String to be converted into JTS {@link Geometry} * @return JTS Geometry from given WKT String * @throws ParseException if WKT string cannot be parsed */ private static Geometry toGeometry(String wellKnownText) throws ParseException { WKTReader wktReader = new WKTReader(getGeometryFactory()); return wktReader.read(wellKnownText); }