Search in sources :

Example 16 with Envelope

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

the class MutableTree method createFromPaths.

public static MutableTree createFromPaths(final ObjectId rootId, final Map<String, NodeRef> entries) {
    List<NodeRef> refsByDepth = Lists.newArrayList(entries.values());
    Collections.sort(refsByDepth, DEEPEST_LAST_COMPARATOR);
    Node rootNode = Node.create(ROOT, rootId, ObjectId.NULL, TYPE.TREE, null);
    MutableTree root = new MutableTree(rootNode);
    Envelope bounds = new Envelope();
    for (NodeRef entry : refsByDepth) {
        Node node = entry.getNode();
        node.expand(bounds);
        String parentPath = entry.getParentPath();
        root.setChild(parentPath, node);
    }
    // recreate root node with the appropriate bounds
    rootNode = Node.create(ROOT, rootId, ObjectId.NULL, TYPE.TREE, bounds);
    root.setNode(rootNode);
    return root;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 17 with Envelope

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

the class RevTreeSerializationTest method createBuckets.

private Map<Integer, Bucket> createBuckets(int count) {
    Map<Integer, Bucket> buckets = Maps.newHashMap();
    for (int i = 0; i < count; i++) {
        Bucket bucket = Bucket.create(ObjectId.forString("b" + i), new Envelope(i, i * 2, i, i * 2));
        buckets.put(i, bucket);
    }
    return buckets;
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 18 with Envelope

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

the class WriteTree2Test method feature.

private Node feature(ObjectDatabase db, String idPrefix, int index) {
    final String id = idPrefix + "." + index;
    final Feature feature;
    try {
        feature = super.feature(pointsType, id, id, index, point(index));
    } catch (ParseException e) {
        throw Throwables.propagate(e);
    }
    RevFeature revFeature = RevFeatureBuilder.build(feature);
    db.put(revFeature);
    Envelope bounds = (Envelope) feature.getBounds();
    return Node.create(id, revFeature.getId(), ObjectId.NULL, TYPE.FEATURE, bounds);
}
Also used : RevFeature(org.locationtech.geogig.api.RevFeature) ParseException(com.vividsolutions.jts.io.ParseException) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature)

Example 19 with Envelope

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

the class WriteTree2Test method tree.

/**
     * Creates a tree reference for testing, forcing the specified id and metadata id, and with the
     * specified number of features (zero or more).
     * <p>
     * Note the tree is saved to the specified database only if its a leaf tree (more than zero
     * features), in order for the {@link #createFromRefs} method to be able of saving the parent
     */
private NodeRef tree(ObjectDatabase db, String path, String id, String mdId, int numFeatures) {
    Preconditions.checkArgument(numFeatures != 0 || EMPTY_ID.equals(id), "for zero features trees use RevTree.EMPTY_TREE_ID");
    final ObjectId treeId = id(id);
    final ObjectId metadataId = id(mdId);
    final String feturePrefix = NodeRef.nodeFromPath(path);
    RevTreeBuilder b = new RevTreeBuilder(db);
    if (numFeatures > 0) {
        for (int i = 0; i < numFeatures; i++) {
            Node fn = feature(db, feturePrefix, i);
            b.put(fn);
        }
    }
    RevTree fakenId = forceTreeId(b, treeId);
    if (!db.exists(fakenId.getId())) {
        db.put(fakenId);
    }
    if (!metadataId.isNull()) {
        RevFeatureType fakeType = new RevFeatureTypeImpl(metadataId, pointsType);
        if (!db.exists(fakeType.getId())) {
            db.put(fakeType);
        }
    }
    String name = NodeRef.nodeFromPath(path);
    String parent = NodeRef.parentPath(path);
    Envelope bounds = SpatialOps.boundsOf(fakenId);
    Node node = Node.create(name, treeId, metadataId, TYPE.TREE, bounds);
    return new NodeRef(node, parent, ObjectId.NULL);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevFeatureTypeImpl(org.locationtech.geogig.api.RevFeatureTypeImpl) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 20 with Envelope

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

the class OSMExport method getFeatures.

private Iterator<EntityContainer> getFeatures(String ref) {
    Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(ref).call();
    if (!id.isPresent()) {
        return Iterators.emptyIterator();
    }
    LsTreeOp op = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
    if (bbox != null) {
        final Envelope env;
        try {
            env = new Envelope(Double.parseDouble(bbox.get(0)), Double.parseDouble(bbox.get(2)), Double.parseDouble(bbox.get(1)), Double.parseDouble(bbox.get(3)));
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Wrong bbox definition");
        }
        Predicate<Bounded> filter = new Predicate<Bounded>() {

            @Override
            public boolean apply(final Bounded bounded) {
                boolean intersects = bounded.intersects(env);
                return intersects;
            }
        };
        op.setBoundsFilter(filter);
    }
    Iterator<NodeRef> iterator = op.call();
    final EntityConverter converter = new EntityConverter();
    Function<NodeRef, EntityContainer> function = new Function<NodeRef, EntityContainer>() {

        @Override
        @Nullable
        public EntityContainer apply(@Nullable NodeRef ref) {
            RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
            SimpleFeatureType featureType;
            if (ref.path().startsWith(OSMUtils.NODE_TYPE_NAME)) {
                featureType = OSMUtils.nodeType();
            } else {
                featureType = OSMUtils.wayType();
            }
            SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
            RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
            List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < descriptors.size(); i++) {
                PropertyDescriptor descriptor = descriptors.get(i);
                Optional<Object> value = values.get(i);
                featureBuilder.set(descriptor.getName(), value.orNull());
            }
            SimpleFeature feature = featureBuilder.buildFeature(ref.name());
            Entity entity = converter.toEntity(feature, null);
            EntityContainer container;
            if (entity instanceof Node) {
                container = new NodeContainer((Node) entity);
            } else {
                container = new WayContainer((Way) entity);
            }
            return container;
        }
    };
    return Iterators.transform(iterator, function);
}
Also used : EntityConverter(org.locationtech.geogig.osm.internal.EntityConverter) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Envelope(com.vividsolutions.jts.geom.Envelope) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Predicate(com.google.common.base.Predicate) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) Bounded(org.locationtech.geogig.api.Bounded) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

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