Search in sources :

Example 66 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class GeogigSimpleFeature method getBounds.

@Override
public BoundingBox getBounds() {
    CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem();
    Envelope bounds = ReferencedEnvelope.create(crs);
    if (node == null) {
        Optional<Object> o;
        List<Optional<Object>> values = getValues();
        for (int i = 0; i < values.size(); i++) {
            o = values.get(i);
            if (o.isPresent() && o.get() instanceof Geometry) {
                Geometry g = (Geometry) o.get();
                // crs as the feature type
                if (bounds.isNull()) {
                    bounds.init(JTS.bounds(g, crs));
                } else {
                    bounds.expandToInclude(JTS.bounds(g, crs));
                }
            }
        }
    } else {
        node.expand(bounds);
    }
    return (BoundingBox) bounds;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Optional(com.google.common.base.Optional) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope) Point(com.vividsolutions.jts.geom.Point)

Example 67 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class GeogigFeatureReader method getQueryBounds.

private ReferencedEnvelope getQueryBounds(Filter filterInNativeCrs, NodeRef typeTreeRef) {
    CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem();
    if (crs == null) {
        crs = DefaultEngineeringCRS.GENERIC_2D;
    }
    ReferencedEnvelope queryBounds = new ReferencedEnvelope(crs);
    @SuppressWarnings("unchecked") List<ReferencedEnvelope> bounds = (List<ReferencedEnvelope>) filterInNativeCrs.accept(new ExtractBounds(crs), null);
    if (bounds != null && !bounds.isEmpty()) {
        expandToInclude(queryBounds, bounds);
        ReferencedEnvelope fullBounds;
        fullBounds = new ReferencedEnvelope(crs);
        typeTreeRef.expand(fullBounds);
        Envelope clipped = fullBounds.intersection(queryBounds);
        LOGGER.trace("query bounds: {}", queryBounds);
        queryBounds = new ReferencedEnvelope(crs);
        queryBounds.expandToInclude(clipped);
        LOGGER.trace("clipped query bounds: {}", queryBounds);
        if (queryBounds.equals(fullBounds)) {
            queryBounds.setToNull();
        }
    }
    return queryBounds;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 68 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class FormatCommonV1 method readNode.

public static Node readNode(DataInput in) throws IOException {
    final String name = in.readUTF();
    final byte[] objectId = new byte[20];
    in.readFully(objectId);
    final byte[] metadataId = new byte[20];
    in.readFully(metadataId);
    final RevObject.TYPE contentType = RevObject.TYPE.valueOf(in.readByte());
    final Envelope bbox = readBBox(in);
    final Node node;
    node = Node.create(name, ObjectId.createNoClone(objectId), ObjectId.createNoClone(metadataId), contentType, bbox);
    return node;
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 69 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class FormatCommonV2 method writeTree.

public static void writeTree(RevTree tree, DataOutput data) throws IOException {
    writeUnsignedVarLong(tree.size(), data);
    writeUnsignedVarInt(tree.numTrees(), data);
    Envelope envBuff = new Envelope();
    final int nFeatures = tree.features().isPresent() ? tree.features().get().size() : 0;
    writeUnsignedVarInt(nFeatures, data);
    if (nFeatures > 0) {
        for (Node feature : tree.features().get()) {
            writeNode(feature, data, envBuff);
        }
    }
    final int nTrees = tree.trees().isPresent() ? tree.trees().get().size() : 0;
    writeUnsignedVarInt(nTrees, data);
    if (nTrees > 0) {
        for (Node subTree : tree.trees().get()) {
            writeNode(subTree, data, envBuff);
        }
    }
    final int nBuckets = tree.buckets().isPresent() ? tree.buckets().get().size() : 0;
    writeUnsignedVarInt(nBuckets, data);
    if (tree.buckets().isPresent()) {
        ImmutableSortedMap<Integer, Bucket> buckets = tree.buckets().get();
        for (Map.Entry<Integer, Bucket> bucket : buckets.entrySet()) {
            writeBucket(bucket.getKey(), bucket.getValue(), data, envBuff);
        }
    }
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap)

Example 70 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class PreOrderDiffWalk method walk.

/**
     * Walk up the differences between the two trees and emit events to the {@code consumer}.
     * <p>
     * If the two root trees are not equal, an initial call to {@link Consumer#tree(Node, Node)}
     * will be made where the nodes will have {@link NodeRef#ROOT the root name} (i.e. empty
     * string), and provided the consumer indicates to continue with the traversal, further calls to
     * {@link Consumer#feature}, {@link Consumer#tree}, and/or {@link Consumer#bucket} will be made
     * as changes between the two trees are found.
     * <p>
     * At any time, if {@link Consumer#tree} or {@link Consumer#bucket} returns {@code false}, that
     * pair of trees won't be further evaluated and the traversal continues with their siblings or
     * parents if there are no more siblings.
     * <p>
     * Note the {@code consumer} is only notified of nodes or buckets that differ, using
     * {@code null} of either the left of right argument to indicate there's no matching object at
     * the left or right side of the comparison. Left side nulls indicate a new object, right side
     * nulls a deleted one. None of the {@code Consumer} method is ever called with equal left and
     * right arguments.
     * 
     * @param consumer the callback object that gets notified of changes between the two trees and
     *        can abort the walk for whole subtrees.
     */
public final void walk(Consumer consumer) {
    if (left.equals(right)) {
        return;
    }
    // start by asking the consumer if go on with the walk at all with the
    // root nodes
    Envelope lbounds = SpatialOps.boundsOf(left);
    Node lnode = Node.create(NodeRef.ROOT, left.getId(), ObjectId.NULL, TYPE.TREE, lbounds);
    Envelope rbounds = SpatialOps.boundsOf(right);
    Node rnode = Node.create(NodeRef.ROOT, right.getId(), ObjectId.NULL, TYPE.TREE, rbounds);
    if (consumer.tree(lnode, rnode)) {
        traverseTree(consumer, left, right, 0);
    }
    consumer.endTree(lnode, rnode);
}
Also used : Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)111 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Node (org.locationtech.geogig.api.Node)16 Geometry (com.vividsolutions.jts.geom.Geometry)13 ObjectId (org.locationtech.geogig.api.ObjectId)13 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)12 STRtree (com.vividsolutions.jts.index.strtree.STRtree)11 ArrayList (java.util.ArrayList)11 Vertex (org.opentripplanner.routing.graph.Vertex)11 Test (org.junit.Test)9 NodeRef (org.locationtech.geogig.api.NodeRef)9 Edge (org.opentripplanner.routing.graph.Edge)9 LineString (com.vividsolutions.jts.geom.LineString)8 RevTree (org.locationtech.geogig.api.RevTree)8 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 Map (java.util.Map)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 RevFeature (org.locationtech.geogig.api.RevFeature)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5