230231232233234235236237
Geometry g = wkt.read("LINESTRING(0 4,4 0)"); Geometry g2 = wkt.read("LINESTRING(1 1,2 1,2 3)"); LineString l = (LineString) g; LineString l2 = (LineString) g2; PointLineBag bag = l.intersection(l2); assertTrue(!bag.isEmpty()); }
244245246247248249250251
LineString ls = (LineString) g; Geometry g2 = wkt .read("LINESTRING(-2.639991350383829 -1.7999950537374092,-1.8399918576928131 -1.7999950537374092,-1.8399918576928131 -0.9999955610463935,-2.639991350383829 -0.9999955610463935,-2.639991350383829 -1.7999950537374092)"); LineString ls2 = (LineString) g2; PointLineBag bag = ls.intersection(ls2); assertTrue(!bag.isEmpty()); }
258259260261262263264265
LineString ls = (LineString) g; Geometry g2 = wkt .read("LINESTRING(1.0 6.0,5.75429730253235 2.5481140652851213,3.9440778098389764 -3.0413371363465505,-1.9311899958501355 -3.0506944106199967,-3.759204394078429 2.5329623398454943,1.0 6.0)"); LineString ls2 = (LineString) g2; PointLineBag bag = ls.intersection(ls2); assertTrue(!bag.isEmpty()); }
272273274275276277278279
LineString ls = (LineString) g; Geometry g2 = wkt .read("LINESTRING(1.0 6.0,5.328799197461722 3.502298445041029,5.332779000281329 -1.4954009967780992,1.0079632645824363 -3.999993658637697,-3.324808414448497 -1.5091895461115477,-3.3367478128123684 3.488497218818446,1.0 6.0)"); LineString ls2 = (LineString) g2; PointLineBag bag = ls.intersection(ls2); assertTrue(!bag.isEmpty()); }
286287288289290291292293
LineString ls = (LineString) g; Geometry g2 = wkt .read("LINESTRING(3.3400048574815147 -2.1999948000829175,4.140004350172529 -2.1999948000829175,4.140004350172529 -1.399995307391901,3.3400048574815147 -1.399995307391901,3.3400048574815147 -2.1999948000829175)"); LineString ls2 = (LineString) g2; PointLineBag bag = ls.intersection(ls2); assertTrue(!bag.isEmpty()); }
228229230231232233234235236237238239
} private void breakLine(Ring r, List<LineString> lines) { for (int i = 0, n = lines.size(); i < n; i++) { LineString line = lines.get(i); PointLineBag bag = line.intersection(r); List<LineString> newLines = bag.breakLine(line); if (newLines.size() > 1) { lines.remove(i); lines.addAll(newLines); return;
34353637383940414243
public FragmentCollection(Polygon r1, Polygon r2) { if (!r1.isValid() || !r2.isValid()) { throw new GeometryException(); } PointLineBag bag = getIntersection(r1, r2); addPolygon(fragments1, r1, r2, bag); addPolygon(fragments2, r2, r1, bag); }
535455565758596061626364
} return; } private PointLineBag getIntersection(Polygon pg1, Polygon pg2) { PointLineBag tbag = subGetIntersection(pg1.getShell(), pg2); List<Ring> rs = pg1.getHoles(); for (Ring r : rs) { tbag.add(subGetIntersection(r, pg2)); } return tbag; }
626364656667686970717273
} return tbag; } private PointLineBag subGetIntersection(Ring r1, Polygon pg2) { PointLineBag tbag = r1.intersection(pg2.getShell()); List<Ring> rs = pg2.getHoles(); for (Ring r : rs) { tbag.add(r1.intersection(r)); } return tbag; }
184185186187188189190191192
} public PointLineBag intersection(LineString l2) { if (!this.getEnvelop().hasIntersect(l2.getEnvelop())) { return new PointLineBag(); } return LineAlgorithm.intersection(this.points, l2.points); }