locationtech / jts

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.
Other
1.94k stars 442 forks source link

Perf: InteriorPointArea - bisector intersection with geometry #176

Open jandam opened 6 years ago

jandam commented 6 years ago

Geometry intersections = bisector.intersection(geometry); in InteriorPointArea::addPolygon uses general intersection algorithm. We know that bisector is horizontal LineSegment. So there can be specialized algorithm for horizontal/vertical lines. INTERSECTION in OverlayOp can be improved to use segments that fits to horizontal/vertical Interval intersection from both geometries. I think that other segments/monotone chains can be omitted. Example: Czech Republic polygon from OpenStreetMap ~80k nodes -- following can be eliminated if we use only segments/monotone chains that intersects with horizontal line ~22k monotone chains ~44k Mark&Sweep events

Possible issues/regressions I suppose that there can be some problems when SnapIfNeededOverlayOp fallback from OverlayOp to SnapOverlayOp.

dr-jts commented 6 years ago

Good point, using the general intersection algorithm in InteriorPointAreais quite inefficient.

I think this would be improved with a simpler customized HorizontalLineIntersectionalgorithm, rather than trying to change the current overlay algorithm. Of course, this could be provided as a branch in Geomery.intersection by checking for an input of a horizontal line.

On the wish list is a ClipToRectangle algorithm, which might provide this capability as well. Although I suspect that an algorithm specifically for horizontal lines could be even simpler.

dr-jts commented 6 years ago

@jandam Is the OSM polygon dataset publicly available?

jandam commented 6 years ago

Here is polygon of Czech Republic border in WKB format (WGS84) extracted from OpenStreetMap. OSM must be mentioned according to licence. http://www.openstreetmap.org/copyright Source data in PBF format for whole country can be downloaded from http://download.geofabrik.de/europe/czech-republic.html#

czech-republic-poly.zip