Search in sources :

Example 6 with BoundingBox

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

the class ScaledIntegerGriddedDigitalElevationModelFile method createNewFile.

protected void createNewFile() throws IOException {
    Paths.createParentDirectories(this.path);
    this.channel = FileChannel.open(this.path, Paths.OPEN_OPTIONS_READ_WRITE_SET, this.fileAttributes);
    try (final ChannelWriter writer = new ChannelWriter(this.channel)) {
        final int gridWidth = getGridWidth();
        final int gridHeight = getGridHeight();
        final double gridCellSize = getGridCellSize();
        final BoundingBox boundingBox = getBoundingBox();
        final GeometryFactory geometryFactory = getGeometryFactory();
        ScaledIntegerGriddedDigitalElevationModelWriter.writeHeader(writer, boundingBox, geometryFactory, gridWidth, gridHeight, (int) gridCellSize);
        final int count = gridWidth * gridHeight;
        for (int i = 0; i < count; i++) {
            writer.putInt(Integer.MIN_VALUE);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 7 with BoundingBox

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

the class ConformingDelaunayTriangulator method findNonGabrielPoint.

/**
 * Given a set of points stored in the kd-tree and a line segment defined by
 * two points in this set, finds a {@link Coordinates} in the circumcircle of
 * the line segment, if one exists. This is called the Gabriel point - if none
 * exists then the segment is said to have the Gabriel condition. Uses the
 * heuristic of finding the non-Gabriel point closest to the midpoint of the
 * segment.
 *
 * @param p
 *          start of the line segment
 * @param q
 *          end of the line segment
 * @return a point which is non-Gabriel
 * or null if no point is non-Gabriel
 */
private Point findNonGabrielPoint(final LineSegmentDoubleData seg) {
    final Point p = seg.getPoint(0);
    final Point q = seg.getPoint(1);
    // Find the mid point on the line and compute the radius of enclosing circle
    final Point midPt = new PointDoubleXY((p.getX() + q.getX()) / 2.0, (p.getY() + q.getY()) / 2.0);
    final double segRadius = p.distancePoint(midPt);
    // compute envelope of circumcircle
    final BoundingBox env = midPt.getBoundingBox().expand(segRadius);
    // Find all points in envelope
    final List result = this.pointIndex.getItems(env);
    // For each point found, test if it falls strictly in the circle
    // find closest point
    Point closestNonGabriel = null;
    double minDist = Double.MAX_VALUE;
    for (final Iterator i = result.iterator(); i.hasNext(); ) {
        final KdNode nextNode = (KdNode) i.next();
        final Point testPt = nextNode;
        // ignore segment endpoints
        if (testPt.equals(2, p) || testPt.equals(2, q)) {
            continue;
        }
        final double testRadius = midPt.distancePoint(testPt);
        if (testRadius < segRadius) {
            // double testDist = seg.distance(testPt);
            final double testDist = testRadius;
            if (closestNonGabriel == null || testDist < minDist) {
                closestNonGabriel = testPt;
                minDist = testDist;
            }
        }
    }
    return closestNonGabriel;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) KdNode(com.revolsys.geometry.index.kdtree.KdNode) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 8 with BoundingBox

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

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

the class Graph method getEdges.

public List<Edge<T>> getEdges(final Point point, final double maxDistance) {
    if (point == null) {
        return Collections.emptyList();
    } else {
        BoundingBox boundingBox = point.getBoundingBox();
        boundingBox = boundingBox.expand(maxDistance);
        final double x = point.getX();
        final double y = point.getY();
        final Predicate<Edge<T>> filter = (edge) -> {
            final LineString line = edge.getLineString();
            final double distance = line.distance(x, y);
            if (distance <= maxDistance) {
                return true;
            } else {
                return false;
            }
        };
        return BoundingBox.newArraySorted(this::forEachEdge, boundingBox, filter);
    }
}
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) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 10 with BoundingBox

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

the class RectangleXY method isWithinDistance.

@Override
public boolean isWithinDistance(Geometry geometry, final double distance) {
    geometry = geometry.as2d(this);
    final BoundingBox boundingBox2 = geometry.getBoundingBox();
    final double bboxDistance = boundingBox2.distance(this.minX, this.minY, this.maxX, this.maxY);
    if (bboxDistance > distance) {
        return false;
    } else {
        final double geometryDistance = this.distance(geometry);
        return geometryDistance <= distance;
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox)

Aggregations

BoundingBox (com.revolsys.geometry.model.BoundingBox)307 Point (com.revolsys.geometry.model.Point)83 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)76 ArrayList (java.util.ArrayList)45 Geometry (com.revolsys.geometry.model.Geometry)41 LineString (com.revolsys.geometry.model.LineString)26 List (java.util.List)26 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)19 Polygon (com.revolsys.geometry.model.Polygon)14 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)14 Project (com.revolsys.swing.map.layer.Project)14 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)12 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)11 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)11 Edge (com.revolsys.geometry.graph.Edge)10 HashMap (java.util.HashMap)10 Record (com.revolsys.record.Record)9 Graphics2D (java.awt.Graphics2D)9 MapEx (com.revolsys.collection.map.MapEx)8 LinearRing (com.revolsys.geometry.model.LinearRing)8