Search in sources :

Example 1 with TopologyException

use of com.revolsys.geometry.model.TopologyException in project com.revolsys.open by revolsys.

the class EdgeRing method computePoints.

/**
 * Collect all the points from the DirectedEdges of this ring into a contiguous list
 */
private void computePoints(final DirectedEdge start) {
    final LineStringEditor points = new LineStringEditor(2, 10);
    this.startDe = start;
    DirectedEdge de = start;
    boolean isFirstEdge = true;
    do {
        // Assert.isTrue(de != null, "found null Directed Edge");
        if (de == null) {
            throw new TopologyException("Found null DirectedEdge");
        }
        if (de.getEdgeRing() == this) {
            throw new TopologyException("Directed Edge visited twice during ring-building at " + de.getCoordinate());
        }
        this.edges.add(de);
        final Label label = de.getLabel();
        if (!label.isArea()) {
            throw new IllegalStateException("Label is not an area");
        }
        mergeLabel(label);
        addPoints(points, de.getEdge(), de.isForward(), isFirstEdge);
        isFirstEdge = false;
        setEdgeRing(de, this);
        de = getNext(de);
    } while (de != this.startDe);
    this.ring = points.newLinearRing();
    this.isHole = this.ring.isCounterClockwise();
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) TopologyException(com.revolsys.geometry.model.TopologyException)

Example 2 with TopologyException

use of com.revolsys.geometry.model.TopologyException in project com.revolsys.open by revolsys.

the class FastNodingValidator method checkValid.

/**
 * Checks for an intersection and throws
 * a TopologyException if one is found.
 *
 * @throws TopologyException if an intersection is found
 */
public void checkValid() {
    execute();
    if (!this.isValid) {
        final String errorMessage = getErrorMessage();
        final Point interiorIntersection = this.segInt.getInteriorIntersection();
        throw new TopologyException(errorMessage, interiorIntersection);
    }
}
Also used : Point(com.revolsys.geometry.model.Point) TopologyException(com.revolsys.geometry.model.TopologyException)

Example 3 with TopologyException

use of com.revolsys.geometry.model.TopologyException in project com.revolsys.open by revolsys.

the class ConsistentPolygonRingChecker method testLinkResultDirectedEdges.

private void testLinkResultDirectedEdges(final DirectedEdgeStar deStar, final int opCode) {
    // make sure edges are copied to resultAreaEdges list
    final List ringEdges = getPotentialResultAreaEdges(deStar, opCode);
    // find first area edge (if any) to start linking at
    DirectedEdge firstOut = null;
    DirectedEdge incoming = null;
    int state = this.SCANNING_FOR_INCOMING;
    // link edges in CCW order
    for (int i = 0; i < ringEdges.size(); i++) {
        final DirectedEdge nextOut = (DirectedEdge) ringEdges.get(i);
        final DirectedEdge nextIn = nextOut.getSym();
        // skip de's that we're not interested in
        if (!nextOut.getLabel().isArea()) {
            continue;
        }
        // record first outgoing edge, in order to link the last incoming edge
        if (firstOut == null && isPotentialResultAreaEdge(nextOut, opCode)) {
            firstOut = nextOut;
        // assert: sym.isInResult() == false, since pairs of dirEdges should
        // have been removed already
        }
        switch(state) {
            case SCANNING_FOR_INCOMING:
                if (!isPotentialResultAreaEdge(nextIn, opCode)) {
                    continue;
                }
                incoming = nextIn;
                state = this.LINKING_TO_OUTGOING;
                break;
            case LINKING_TO_OUTGOING:
                if (!isPotentialResultAreaEdge(nextOut, opCode)) {
                    continue;
                }
                // incoming.setNext(nextOut);
                state = this.SCANNING_FOR_INCOMING;
                break;
        }
    }
    // Debug.print(this);
    if (state == this.LINKING_TO_OUTGOING) {
        // Debug.print(firstOut == null, this);
        if (firstOut == null) {
            throw new TopologyException("no outgoing dirEdge found", deStar.getCoordinate());
        }
    }
}
Also used : DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) List(java.util.List) ArrayList(java.util.ArrayList) TopologyException(com.revolsys.geometry.model.TopologyException)

Example 4 with TopologyException

use of com.revolsys.geometry.model.TopologyException in project com.revolsys.open by revolsys.

the class FilterMultipleRenderer method renderRecords.

@Override
protected void renderRecords(final Viewport2D viewport, final Cancellable cancellable, final AbstractRecordLayer layer, final List<LayerRecord> records) {
    final Map<AbstractRecordLayerRenderer, List<LayerRecord>> rendererToRecordMap = new LinkedHashMap<>();
    final BoundingBox visibleArea = viewport.getBoundingBox();
    final double scaleForVisible = viewport.getScaleForVisible();
    if (isVisible(scaleForVisible)) {
        final List<AbstractRecordLayerRenderer> renderers = new ArrayList<>(getRenderers());
        for (final AbstractRecordLayerRenderer renderer : renderers) {
            rendererToRecordMap.put(renderer, new ArrayList<>());
        }
        for (final LayerRecord record : cancellable.cancellable(records)) {
            if (isFilterAccept(record) && !layer.isHidden(record)) {
                final AbstractRecordLayerRenderer renderer = getRenderer(layer, renderers, record, scaleForVisible);
                if (renderer != null) {
                    Maps.addToList(rendererToRecordMap, renderer, record);
                }
            }
        }
        for (final Entry<AbstractRecordLayerRenderer, List<LayerRecord>> entry : cancellable.cancellable(rendererToRecordMap.entrySet())) {
            final AbstractRecordLayerRenderer renderer = entry.getKey();
            final List<LayerRecord> rendererRecords = entry.getValue();
            for (final LayerRecord record : cancellable.cancellable(rendererRecords)) {
                try {
                    renderer.renderRecord(viewport, visibleArea, layer, record);
                } catch (final TopologyException e) {
                } catch (final Throwable e) {
                    if (!cancellable.isCancelled()) {
                        Logs.error(this, "Unabled to render " + layer.getName() + " #" + record.getIdentifier(), e);
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TopologyException(com.revolsys.geometry.model.TopologyException) LinkedHashMap(java.util.LinkedHashMap) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 5 with TopologyException

use of com.revolsys.geometry.model.TopologyException in project com.revolsys.open by revolsys.

the class EdgeEndStar method propagateSideLabels.

void propagateSideLabels(final int geomIndex) {
    // Since edges are stored in CCW order around the node,
    // As we move around the ring we move from the right to the left side of the
    // edge
    Location startLoc = Location.NONE;
    // System.out.println("finding start location");
    for (final EdgeEnd e : this) {
        final Label label = e.getLabel();
        if (label.isArea(geomIndex) && label.getLocation(geomIndex, Position.LEFT) != Location.NONE) {
            startLoc = label.getLocation(geomIndex, Position.LEFT);
        }
    }
    // no labelled sides found, so no labels to propagate
    if (startLoc == Location.NONE) {
        return;
    }
    Location currLoc = startLoc;
    for (final EdgeEnd e : this) {
        final Label label = e.getLabel();
        // set null ON values to be in current location
        if (label.getLocation(geomIndex, Position.ON) == Location.NONE) {
            label.setLocation(geomIndex, Position.ON, currLoc);
        }
        // set side labels (if any)
        if (label.isArea(geomIndex)) {
            final Location leftLoc = label.getLocation(geomIndex, Position.LEFT);
            final Location rightLoc = label.getLocation(geomIndex, Position.RIGHT);
            // if there is a right location, that is the next location to propagate
            if (rightLoc != Location.NONE) {
                // Debug.print(rightLoc != currLoc, this);
                if (rightLoc != currLoc) {
                    throw new TopologyException("side location conflict", e.getCoordinate());
                }
                if (leftLoc == Location.NONE) {
                    Assert.shouldNeverReachHere("found single null side (at " + e.getCoordinate() + ")");
                }
                currLoc = leftLoc;
            } else {
                /**
                 * RHS is null - LHS must be null too.
                 *  This must be an edge from the other geometry, which has no location
                 *  labelling for this geometry.  This edge must lie wholly inside or outside
                 *  the other geometry (which is determined by the current location).
                 *  Assign both sides to be the current location.
                 */
                if (label.getLocation(geomIndex, Position.LEFT) != Location.NONE) {
                    throw new IllegalStateException("found single null side");
                }
                label.setLocation(geomIndex, Position.RIGHT, currLoc);
                label.setLocation(geomIndex, Position.LEFT, currLoc);
            }
        }
    }
}
Also used : TopologyException(com.revolsys.geometry.model.TopologyException) Location(com.revolsys.geometry.model.Location)

Aggregations

TopologyException (com.revolsys.geometry.model.TopologyException)8 DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 Point (com.revolsys.geometry.model.Point)2 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DirectedEdgeStar (com.revolsys.geometry.geomgraph.DirectedEdgeStar)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Location (com.revolsys.geometry.model.Location)1 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)1 LinkedHashMap (java.util.LinkedHashMap)1