private void draw( Object parentGroup, GeometryIndex parentIndex, Polygon polygon, GraphicsContext graphics) { String groupName = baseName; if (parentIndex != null) { groupName += "." + editingService.getIndexService().format(parentIndex); } Composite bgGroup = getOrCreateGroup(parentGroup, groupName + ".background"); Composite geometryGroup = getOrCreateGroup(parentGroup, groupName + ".geometries"); // Draw the exterior ring: GeometryIndex shellIndex = editingService .getIndexService() .addChildren(parentIndex, GeometryIndexType.TYPE_GEOMETRY, 0); if (!polygon.isEmpty()) { if (styleService.getBackgroundStyle() != null && styleService.getBackgroundStyle().getFillOpacity() > 0) { graphics.drawPolygon(bgGroup, "background", polygon, findGeometryStyle(shellIndex)); } draw(geometryGroup, shellIndex, polygon.getExteriorRing(), graphics); } // Draw the interior rings: for (int i = 0; i < polygon.getNumInteriorRing(); i++) { GeometryIndex holeIndex = editingService .getIndexService() .addChildren(parentIndex, GeometryIndexType.TYPE_GEOMETRY, i + 1); draw(geometryGroup, holeIndex, polygon.getInteriorRingN(i), graphics); } }
@Test public void testLineStringMiddleIndex() { GeometryOperation op = new RemoveRingOperation(1); Polygon result = (Polygon) op.execute(polygon); Assert.assertEquals(polygon.getNumInteriorRing() - 1, result.getNumInteriorRing()); Assert.assertEquals(12.0, result.getInteriorRingN(0).getCoordinate().getX(), TOLERANCE); }
private void execute(Polygon polygon) { LinearRing ring = null; if (index.isExteriorRing()) { ring = polygon.getExteriorRing(); if (ring == null) { ring = polygon.getGeometryFactory().createLinearRing(new Coordinate[] {coordinate}); setExteriorRing(polygon, ring); } else { setExteriorRing(polygon, (LinearRing) execute(ring)); } } else if (index.getInteriorRingIndex() >= 0) { if (index.getGeometryIndex() >= polygon.getNumInteriorRing()) { LinearRing[] interiorRings = new LinearRing[polygon.getNumInteriorRing() + 1]; for (int i = 0; i < polygon.getNumInteriorRing(); i++) { interiorRings[i] = polygon.getInteriorRingN(i); } interiorRings[polygon.getNumInteriorRing()] = polygon.getGeometryFactory().createLinearRing(new Coordinate[] {coordinate}); setInteriorRings(polygon, interiorRings); } else { ring = polygon.getInteriorRingN(index.getInteriorRingIndex()); LineString lineString = execute(ring); setInteriorRingN(polygon, (LinearRing) lineString, index.getInteriorRingIndex()); } } }
private void undo(Polygon polygon) { LinearRing ring = null; if (index.isExteriorRing()) { ring = polygon.getExteriorRing(); LineString lineString = undo(ring); setExteriorRing(polygon, (LinearRing) lineString); } else if (index.getInteriorRingIndex() >= 0) { ring = polygon.getInteriorRingN(index.getInteriorRingIndex()); LineString lineString = undo(ring); setInteriorRingN(polygon, (LinearRing) lineString, index.getInteriorRingIndex()); } }