@Test public void testHoleAssignment() { java.awt.Dimension ps = new java.awt.Dimension(500, 500); PrecisionModel precision = new PrecisionModel(); ArrayList<LinearRing> shells = new ArrayList<>(); ArrayList<LinearRing> holes = new ArrayList<>(); int x = 10; int y = 10; shells.add(copyTo(x, y, ps.width - 2 * x, ps.height - 2 * y, rectangle(precision, 0))); int w = 11; int h = 11; int s = 10; int nx = (ps.width - 2 * x) / (w + s); int ny = (ps.height - 2 * y) / (h + s); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { holes.add( copyTo( x + s + i * (w + s), y + s + j * (h + s), w, h, rectangle(precision, 0))); } } PolygonHandler ph = new PolygonHandler(new GeometryFactory()); List<List<LinearRing>> assigned = ph.assignHolesToShells(shells, holes); assertEquals(holes.size(), assigned.get(0).size()); }
List<List<LinearRing>> assignHolesToShells( final ArrayList<LinearRing> shells, final ArrayList<LinearRing> holes) { List<List<LinearRing>> holesForShells = new ArrayList<>(shells.size()); for (int i = 0; i < shells.size(); i++) { holesForShells.add(new ArrayList<>()); } for (int i = 0; i < holes.size(); i++) { LinearRing testRing = (LinearRing) holes.get(i); LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; for (int j = 0; j < shells.size(); j++) { tryRing = shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); } boolean isContained = false; Coordinate[] coordList = tryRing.getCoordinates(); if (tryEnv.contains(testEnv) && (RayCrossingCounter.locatePointInRing(testPt, coordList) != 2 || (pointInList(testPt, coordList)))) { isContained = true; } if (isContained) { if ((minShell == null) || minEnv.contains(tryEnv)) { minShell = tryRing; } } } if (minShell == null) { shells.add(testRing); holesForShells.add(new ArrayList<>()); } else { holesForShells.get(shells.indexOf(minShell)).add(testRing); } } return holesForShells; }
PolygonHandler implements ShapeHandler { List<List<LinearRing>> assignHolesToShells( final ArrayList<LinearRing> shells, final ArrayList<LinearRing> holes) { List<List<LinearRing>> holesForShells = new ArrayList<>(shells.size()); for (int i = 0; i < shells.size(); i++) { holesForShells.add(new ArrayList<>()); } for (int i = 0; i < holes.size(); i++) { LinearRing testRing = (LinearRing) holes.get(i); LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; for (int j = 0; j < shells.size(); j++) { tryRing = shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); } boolean isContained = false; Coordinate[] coordList = tryRing.getCoordinates(); if (tryEnv.contains(testEnv) && (RayCrossingCounter.locatePointInRing(testPt, coordList) != 2 || (pointInList(testPt, coordList)))) { isContained = true; } if (isContained) { if ((minShell == null) || minEnv.contains(tryEnv)) { minShell = tryRing; } } } if (minShell == null) { shells.add(testRing); holesForShells.add(new ArrayList<>()); } else { holesForShells.get(shells.indexOf(minShell)).add(testRing); } } return holesForShells; } }
PolygonHandler implements ShapeHandler { List<List<LinearRing>> assignHolesToShells( final ArrayList<LinearRing> shells, final ArrayList<LinearRing> holes) { List<List<LinearRing>> holesForShells = new ArrayList<>(shells.size()); for (int i = 0; i < shells.size(); i++) { holesForShells.add(new ArrayList<>()); } for (int i = 0; i < holes.size(); i++) { LinearRing testRing = (LinearRing) holes.get(i); LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; for (int j = 0; j < shells.size(); j++) { tryRing = shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); } boolean isContained = false; Coordinate[] coordList = tryRing.getCoordinates(); if (tryEnv.contains(testEnv) && (RayCrossingCounter.locatePointInRing(testPt, coordList) != 2 || (pointInList(testPt, coordList)))) { isContained = true; } if (isContained) { if ((minShell == null) || minEnv.contains(tryEnv)) { minShell = tryRing; } } } if (minShell == null) { shells.add(testRing); holesForShells.add(new ArrayList<>()); } else { holesForShells.get(shells.indexOf(minShell)).add(testRing); } } return holesForShells; } PolygonHandler(GeometryFactory gf);  PolygonHandler(ShapeType type, GeometryFactory gf); }
PolygonHandler implements ShapeHandler { List<List<LinearRing>> assignHolesToShells( final ArrayList<LinearRing> shells, final ArrayList<LinearRing> holes) { List<List<LinearRing>> holesForShells = new ArrayList<>(shells.size()); for (int i = 0; i < shells.size(); i++) { holesForShells.add(new ArrayList<>()); } for (int i = 0; i < holes.size(); i++) { LinearRing testRing = (LinearRing) holes.get(i); LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; for (int j = 0; j < shells.size(); j++) { tryRing = shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); } boolean isContained = false; Coordinate[] coordList = tryRing.getCoordinates(); if (tryEnv.contains(testEnv) && (RayCrossingCounter.locatePointInRing(testPt, coordList) != 2 || (pointInList(testPt, coordList)))) { isContained = true; } if (isContained) { if ((minShell == null) || minEnv.contains(tryEnv)) { minShell = tryRing; } } } if (minShell == null) { shells.add(testRing); holesForShells.add(new ArrayList<>()); } else { holesForShells.get(shells.indexOf(minShell)).add(testRing); } } return holesForShells; } PolygonHandler(GeometryFactory gf);  PolygonHandler(ShapeType type, GeometryFactory gf); ShapeType getShapeType(); int getLength(Object geometry); Object read(ByteBuffer buffer, ShapeType type, boolean flatFeature); void write(ByteBuffer buffer, Object geometry); }
PolygonHandler implements ShapeHandler { List<List<LinearRing>> assignHolesToShells( final ArrayList<LinearRing> shells, final ArrayList<LinearRing> holes) { List<List<LinearRing>> holesForShells = new ArrayList<>(shells.size()); for (int i = 0; i < shells.size(); i++) { holesForShells.add(new ArrayList<>()); } for (int i = 0; i < holes.size(); i++) { LinearRing testRing = (LinearRing) holes.get(i); LinearRing minShell = null; Envelope minEnv = null; Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); LinearRing tryRing; for (int j = 0; j < shells.size(); j++) { tryRing = shells.get(j); Envelope tryEnv = tryRing.getEnvelopeInternal(); if (minShell != null) { minEnv = minShell.getEnvelopeInternal(); } boolean isContained = false; Coordinate[] coordList = tryRing.getCoordinates(); if (tryEnv.contains(testEnv) && (RayCrossingCounter.locatePointInRing(testPt, coordList) != 2 || (pointInList(testPt, coordList)))) { isContained = true; } if (isContained) { if ((minShell == null) || minEnv.contains(tryEnv)) { minShell = tryRing; } } } if (minShell == null) { shells.add(testRing); holesForShells.add(new ArrayList<>()); } else { holesForShells.get(shells.indexOf(minShell)).add(testRing); } } return holesForShells; } PolygonHandler(GeometryFactory gf);  PolygonHandler(ShapeType type, GeometryFactory gf); ShapeType getShapeType(); int getLength(Object geometry); Object read(ByteBuffer buffer, ShapeType type, boolean flatFeature); void write(ByteBuffer buffer, Object geometry);  }