Search in sources :

Example 1 with Geometry

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

the class InteriorPointArea method widestGeometry.

// @return if geometry is a collection, the widest sub-geometry; otherwise,
// the geometry itself
private Geometry widestGeometry(final Geometry geometry) {
    if (geometry.isGeometryCollection()) {
        if (geometry.isEmpty()) {
            return geometry;
        } else {
            double widestWidth = 0;
            Geometry widestGeometry = null;
            // scan remaining geom components to see if any are wider
            for (final Geometry part : geometry.geometries()) {
                final double width = part.getBoundingBox().getWidth();
                if (widestGeometry == null || width > widestWidth) {
                    widestGeometry = part;
                    widestWidth = width;
                }
            }
            return widestGeometry;
        }
    } else {
        return geometry;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry)

Example 2 with Geometry

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

the class Graph method getNodes.

public List<Node<T>> getNodes(final Predicate<Node<T>> filter, final Geometry geometry, final double maxDistance) {
    final BoundingBox boundingBox = geometry.getBoundingBox().expand(maxDistance);
    final Predicate<Node<T>> distanceFilter = (node) -> {
        return filter.test(node) && node.distance(geometry) <= maxDistance;
    };
    return getNodes(boundingBox, distanceFilter, null);
}
Also used : Arrays(java.util.Arrays) ComparatorProxy(com.revolsys.comparator.ComparatorProxy) IdObjectIndex(com.revolsys.geometry.index.IdObjectIndex) LineSegmentUtil(com.revolsys.geometry.model.coordinates.LineSegmentUtil) EdgeEvent(com.revolsys.geometry.graph.event.EdgeEvent) PreDestroy(javax.annotation.PreDestroy) GeometryFactoryProxy(com.revolsys.geometry.model.GeometryFactoryProxy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) PredicateProxy(com.revolsys.predicate.PredicateProxy) Method(java.lang.reflect.Method) PointComparators(com.revolsys.geometry.model.coordinates.comparator.PointComparators) NodeProperties(com.revolsys.geometry.graph.attribute.NodeProperties) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) IntHashMap(com.revolsys.collection.map.IntHashMap) EdgeEventListenerList(com.revolsys.geometry.graph.event.EdgeEventListenerList) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) List(java.util.List) NodeEventListener(com.revolsys.geometry.graph.event.NodeEventListener) Entry(java.util.Map.Entry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ExitLoopException(com.revolsys.util.ExitLoopException) Point(com.revolsys.geometry.model.Point) EdgeEventListener(com.revolsys.geometry.graph.event.EdgeEventListener) NodeWithinBoundingBoxVisitor(com.revolsys.geometry.graph.visitor.NodeWithinBoundingBoxVisitor) LineString(com.revolsys.geometry.model.LineString) HashMap(java.util.HashMap) CreateListVisitor(com.revolsys.visitor.CreateListVisitor) Record(com.revolsys.record.Record) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BPlusTreeMap(com.revolsys.collection.bplus.BPlusTreeMap) CoordinatesDistanceComparator(com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator) MapEx(com.revolsys.collection.map.MapEx) SerializablePageValueManager(com.revolsys.io.page.SerializablePageValueManager) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) PageValueManager(com.revolsys.io.page.PageValueManager) IsPointOnLineEdgeFilter(com.revolsys.geometry.graph.filter.IsPointOnLineEdgeFilter) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble) NodeEvent(com.revolsys.geometry.graph.event.NodeEvent) Consumer(java.util.function.Consumer) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) TreeMap(java.util.TreeMap) BoundingBoxProxy(com.revolsys.geometry.model.BoundingBoxProxy) Predicates(com.revolsys.predicate.Predicates) NodeDistanceComparator(com.revolsys.geometry.graph.comparator.NodeDistanceComparator) Comparator(java.util.Comparator) NodeEventListenerList(com.revolsys.geometry.graph.event.NodeEventListenerList) Geometry(com.revolsys.geometry.model.Geometry) BaseObjectWithProperties(com.revolsys.properties.BaseObjectWithProperties) Collections(java.util.Collections) BoundingBox(com.revolsys.geometry.model.BoundingBox) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 3 with Geometry

use of com.revolsys.geometry.model.Geometry 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 4 with Geometry

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

the class LineStringGraph method isSimple.

public boolean isSimple() {
    for (final Node<LineSegment> node : getNodes()) {
        if (node.getDegree() > 2) {
            return false;
        }
    }
    for (final Edge<LineSegment> edge : getEdges()) {
        final LineSegment line = edge.getObject();
        final EdgeObjectFilter<LineSegment> filter = new EdgeObjectFilter<>(new LineSegmentIntersectingFilter(line));
        final List<Edge<LineSegment>> edges = getEdges(line, filter);
        for (final Edge<LineSegment> edge2 : edges) {
            final LineSegment line2 = edge2.getObject();
            final Geometry intersections = line.getIntersection(line2);
            if (intersections instanceof LineSegment) {
                return false;
            } else if (intersections instanceof Point) {
                if (edge.getCommonNodes(edge2).isEmpty()) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) EdgeObjectFilter(com.revolsys.geometry.graph.filter.EdgeObjectFilter) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 5 with Geometry

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

the class LineStringGraph method getSelfIntersections.

public Geometry getSelfIntersections() {
    final Set<Point> intersectionPoints = new HashSet<>();
    for (int i = 0; i < this.points.getVertexCount(); i++) {
        final Point point = this.points.getPoint(i);
        final Node<LineSegment> node = getNode(point);
        if (node.getDegree() > 2 || hasTouchingEdges(node)) {
            intersectionPoints.add(point);
        }
    }
    forEachEdge((edge1) -> {
        final LineSegment lineSegment1 = edge1.getObject();
        forEachEdge(edge1, (edge2) -> {
            if (edge1 != edge2) {
                final LineSegment lineSegment2 = edge2.getObject();
                final Geometry intersections = ((LineSegment) lineSegment1.convertGeometry(getGeometryFactory())).getIntersection(lineSegment2);
                for (final Point intersection : intersections.vertices()) {
                    if (!lineSegment1.isEndPoint(intersection) && !lineSegment2.isEndPoint(intersection)) {
                        intersectionPoints.add(intersection);
                    }
                }
            }
        });
    });
    return this.geometryFactory.punctual(intersectionPoints);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) HashSet(java.util.HashSet) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)488 Point (com.revolsys.geometry.model.Point)140 LineString (com.revolsys.geometry.model.LineString)87 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)75 ArrayList (java.util.ArrayList)70 BoundingBox (com.revolsys.geometry.model.BoundingBox)39 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)39 Polygon (com.revolsys.geometry.model.Polygon)34 List (java.util.List)33 Record (com.revolsys.record.Record)32 Iterator (java.util.Iterator)20 RecordDefinition (com.revolsys.record.schema.RecordDefinition)18 LinearRing (com.revolsys.geometry.model.LinearRing)16 Vertex (com.revolsys.geometry.model.vertex.Vertex)16 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)14 LineSegment (com.revolsys.geometry.model.segment.LineSegment)13 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)13 FieldDefinition (com.revolsys.record.schema.FieldDefinition)12 DataType (com.revolsys.datatype.DataType)10 IOException (java.io.IOException)10