Search in sources :

Example 21 with Point

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

the class Graph method addEdge.

/**
 * Actually add the edge.
 *
 * @param object
 * @param line
 * @param from
 * @param to
 * @return
 */
protected Edge<T> addEdge(final T object, final LineString line, final double fromX, final double fromY, final double toX, final double toY) {
    if (this.inMemory && getEdgeCount() >= this.maxEdgesInMemory) {
        this.edgePropertiesById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgePropertiesById);
        // TODO edgIds
        // TODO edgeIndex
        this.edgeLinesById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgeLinesById);
        this.edgeObjectsById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgeObjectsById);
        this.edgesById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgesById);
        // TODO nodeIndex
        this.nodePropertiesById = BPlusTreeMap.newIntSeralizableTempDisk(this.nodePropertiesById);
        this.nodesById = BPlusTreeMap.newIntSeralizableTempDisk(this.nodesById);
        this.nodesIdsByPoint = BPlusTreeMap.newTempDisk(this.nodesIdsByPoint, new SerializablePageValueManager<Point>(), PageValueManager.INT);
        this.inMemory = false;
    }
    final Node<T> fromNode = getNode(fromX, fromY);
    final Node<T> toNode = getNode(toX, toY);
    final int edgeId = ++this.nextEdgeId;
    final Edge<T> edge = new Edge<>(edgeId, this, fromNode, toNode);
    if (this.edgeLinesById != null) {
        this.edgeLinesById.put(edgeId, line);
    }
    this.edgeObjectsById.put(edgeId, object);
    this.edgesById.put(edgeId, edge);
    this.edgeIds.put(edge, edgeId);
    if (this.edgeIndex != null) {
        this.edgeIndex.add(edge);
    }
    this.edgeListeners.edgeEvent(edge, null, EdgeEvent.EDGE_ADDED, null);
    return edge;
}
Also used : SerializablePageValueManager(com.revolsys.io.page.SerializablePageValueManager) Point(com.revolsys.geometry.model.Point)

Example 22 with Point

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

the class RecordGraph method hasEdge.

public boolean hasEdge(final Record record) {
    final LineString line = record.getGeometry();
    final Point fromPoint = line.getPoint(0);
    final Point toPoint = line.getToPoint();
    final Node<Record> fromNode = findNode(fromPoint);
    final Node<Record> toNode = findNode(toPoint);
    if (fromNode != null && toNode != null) {
        final Collection<Edge<Record>> edges = Node.getEdgesBetween(fromNode, toNode);
        for (final Edge<Record> edge : edges) {
            final LineString updateLine = edge.getLineString();
            if (updateLine.equals(line)) {
                return true;
            }
        }
    }
    return false;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) Point(com.revolsys.geometry.model.Point)

Example 23 with Point

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

the class GeometryGraph method addGeometry.

public void addGeometry(Geometry geometry) {
    geometry = getGeometryFactory().geometry(geometry);
    final Map<String, Object> properties = new LinkedHashMap<>();
    final int geometryIndex = this.geometries.size();
    properties.put("geometryIndex", geometryIndex);
    this.geometries.add(geometry);
    for (int partIndex = 0; partIndex < geometry.getGeometryCount(); partIndex++) {
        properties.put("partIndex", partIndex);
        final Geometry part = geometry.getGeometry(partIndex);
        if (part instanceof Point) {
            final Point point = (Point) part;
            this.points.add(point);
        } else if (part instanceof LineString) {
            final LineString line = (LineString) part;
            final LineString points = line;
            properties.put("type", "LineString");
            addEdges(points, properties);
        } else if (part instanceof Polygon) {
            final Polygon polygon = (Polygon) part;
            int ringIndex = 0;
            for (final LinearRing ring : polygon.rings()) {
                properties.put("ringIndex", ringIndex++);
                if (ringIndex == 0) {
                    properties.put("type", "PolygonShell");
                } else {
                    properties.put("type", "PolygonHole");
                }
                addEdges(ring, properties);
            }
            properties.remove("ringIndex");
        }
    }
    this.boundingBox = this.boundingBox.expandToInclude(geometry);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point) LinkedHashMap(java.util.LinkedHashMap)

Example 24 with Point

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

the class LineStringGraph method splitEdge.

@Override
public <V extends Point> List<Edge<LineSegment>> splitEdge(final Edge<LineSegment> edge, final Collection<V> nodes) {
    final List<Edge<LineSegment>> newEdges = new ArrayList<>();
    if (!edge.isRemoved()) {
        final Node<LineSegment> fromNode = edge.getFromNode();
        final Node<LineSegment> toNode = edge.getToNode();
        final CoordinatesDistanceComparator comparator = new CoordinatesDistanceComparator(fromNode.getX(), toNode.getY());
        final Set<Point> newPoints = new TreeSet<>(comparator);
        for (final Point point : nodes) {
            newPoints.add(point);
        }
        newPoints.add(toNode);
        final List<Integer> index = edge.getProperty(INDEX);
        int i = 0;
        Point previousPoint = fromNode;
        for (final Point point : newPoints) {
            final LineSegment lineSegment = new LineSegmentDoubleGF(previousPoint, point);
            final Edge<LineSegment> newEdge = addEdge(lineSegment, previousPoint, point);
            final List<Integer> newIndecies = new ArrayList<>(index);
            newIndecies.add(i++);
            newEdge.setProperty(INDEX, newIndecies);
            newEdges.add(newEdge);
            previousPoint = point;
        }
        remove(edge);
    }
    return newEdges;
}
Also used : CoordinatesDistanceComparator(com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) TreeSet(java.util.TreeSet) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 25 with Point

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

the class LineStringGraph method getLines.

public List<LineString> getLines() {
    removeDuplicateEdges();
    final EdgeAttributeValueComparator<LineSegment> comparator = new EdgeAttributeValueComparator<>("INDEX");
    final List<LineString> lines = new ArrayList<>();
    final List<Point> points = new ArrayList<>();
    final Consumer<Edge<LineSegment>> action = new Consumer<Edge<LineSegment>>() {

        private Node<LineSegment> previousNode = null;

        @Override
        public void accept(final Edge<LineSegment> edge) {
            final LineSegment lineSegment = edge.getObject();
            if (lineSegment.getLength() > 0) {
                final Node<LineSegment> fromNode = edge.getFromNode();
                final Node<LineSegment> toNode = edge.getToNode();
                if (this.previousNode == null) {
                    points.add(lineSegment.getPoint(0));
                    points.add(lineSegment.getPoint(1));
                } else if (fromNode == this.previousNode) {
                    if (edge.getLength() > 0) {
                        points.add(toNode);
                    }
                } else {
                    if (points.size() > 1) {
                        final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
                        lines.add(line);
                    }
                    points.clear();
                    ;
                    points.add(lineSegment.getPoint(0));
                    points.add(lineSegment.getPoint(1));
                }
                if (points.size() > 1) {
                    final int toDegree = toNode.getDegree();
                    if (toDegree != 2) {
                        final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
                        lines.add(line);
                        points.clear();
                        ;
                        points.add(toNode);
                    }
                }
                this.previousNode = toNode;
            }
        }
    };
    forEachEdge(comparator, action);
    if (points.size() > 1) {
        final LineString line = this.geometryFactory.lineString(points);
        lines.add(line);
    }
    return lines;
}
Also used : EdgeAttributeValueComparator(com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Consumer(java.util.function.Consumer) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14