Search in sources :

Example 26 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class Show method printRaw.

private void printRaw(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    for (String ref : refs) {
        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        if (!obj.isPresent()) {
            ref = getFullRef(ref);
            obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        }
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        RevObject revObject = obj.get();
        if (revObject instanceof RevFeature) {
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            if (opt.isPresent()) {
                RevFeatureType ft = opt.get();
                ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                RevFeature feature = (RevFeature) revObject;
                Ansi ansi = super.newAnsi(console.getTerminal());
                ansi.a(ref).newline();
                ansi.a(feature.getId().toString()).newline();
                ImmutableList<Optional<Object>> values = feature.getValues();
                int i = 0;
                for (Optional<Object> value : values) {
                    PropertyDescriptor attrib = attribs.get(i);
                    ansi.a(attrib.getName()).newline();
                    PropertyType attrType = attrib.getType();
                    String typeName = FieldType.forBinding(attrType.getBinding()).name();
                    if (attrType instanceof GeometryType) {
                        GeometryType gt = (GeometryType) attrType;
                        CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                        String crsText = CrsTextSerializer.serialize(crs);
                        ansi.a(typeName).a(" ").a(crsText).newline();
                    } else {
                        ansi.a(typeName).newline();
                    }
                    ansi.a(value.or("[NULL]").toString()).newline();
                    i++;
                }
                console.println(ansi.toString());
            } else {
                CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
                console.println(s);
            }
        } else {
            CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
            console.println(s);
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) PropertyType(org.opengis.feature.type.PropertyType) GeometryType(org.opengis.feature.type.GeometryType) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) CatObject(org.locationtech.geogig.api.plumbing.CatObject) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Ansi(org.fusesource.jansi.Ansi) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 27 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType 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 28 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class PatchSerializationTest method testRemoveEmptyFeatureTypePatch.

@Test
public void testRemoveEmptyFeatureTypePatch() throws Exception {
    Patch patch = new Patch();
    RevFeatureType featureType = RevFeatureTypeImpl.build(pointsType);
    patch.addFeatureType(featureType);
    patch.addAlteredTree(new FeatureTypeDiff(pointsName, featureType.getId(), null));
    testPatch(patch);
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 29 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType 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)

Example 30 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class ImportOpTest method testImportAllWithDifferentFeatureTypesAndDestPathAndAdd.

@Test
public void testImportAllWithDifferentFeatureTypesAndDestPathAndAdd() throws Exception {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setCRS(CRS.decode("EPSG:4326"));
    builder.add("geom", Point.class);
    builder.add("label", String.class);
    builder.setName("dest");
    SimpleFeatureType type = builder.buildFeatureType();
    GeometryFactory gf = new GeometryFactory();
    SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(0, 0)), "feature0" }, "feature");
    geogig.getRepository().workingTree().insert("dest", feature);
    ImportOp importOp = geogig.command(ImportOp.class);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setAll(true);
    importOp.setOverwrite(false);
    importOp.setDestinationPath("dest");
    importOp.setAdaptToDefaultFeatureType(false);
    importOp.call();
    Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
    ArrayList<NodeRef> list = Lists.newArrayList(features);
    assertEquals(5, list.size());
    TreeSet<ObjectId> set = Sets.newTreeSet();
    ArrayList<RevFeatureType> ftlist = new ArrayList<RevFeatureType>();
    for (NodeRef node : list) {
        Optional<RevFeatureType> ft = geogig.command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class);
        assertTrue(ft.isPresent());
        ftlist.add(ft.get());
        set.add(node.getMetadataId());
    }
    assertEquals(4, set.size());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ObjectId(org.locationtech.geogig.api.ObjectId) ArrayList(java.util.ArrayList) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Aggregations

RevFeatureType (org.locationtech.geogig.api.RevFeatureType)88 RevFeature (org.locationtech.geogig.api.RevFeature)49 NodeRef (org.locationtech.geogig.api.NodeRef)40 ObjectId (org.locationtech.geogig.api.ObjectId)34 Test (org.junit.Test)31 Optional (com.google.common.base.Optional)28 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)26 RevObject (org.locationtech.geogig.api.RevObject)24 RevTree (org.locationtech.geogig.api.RevTree)24 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)22 SimpleFeature (org.opengis.feature.simple.SimpleFeature)19 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)17 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)14 ImmutableList (com.google.common.collect.ImmutableList)13 File (java.io.File)13 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)13 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)13 List (java.util.List)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)12 AddOp (org.locationtech.geogig.api.porcelain.AddOp)12