Search in sources :

Example 1 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class WorkingTreeInsertHelper method getTreeBuilder.

private RevTreeBuilder2 getTreeBuilder(final Feature feature) {
    final String treePath = treePathResolver.apply(feature);
    RevTreeBuilder2 builder = treeBuilders.get(treePath);
    if (builder == null) {
        FeatureType type = feature.getType();
        builder = createBuilder(treePath, type);
        treeBuilders.put(treePath, builder);
    }
    return builder;
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 2 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class WorkingTreeInsertHelper method put.

public Node put(final ObjectId revFeatureId, final Feature feature) {
    final RevTreeBuilder2 treeBuilder = getTreeBuilder(feature);
    String fid = feature.getIdentifier().getID();
    BoundingBox bounds = feature.getBounds();
    FeatureType type = feature.getType();
    final Node node = treeBuilder.putFeature(revFeatureId, fid, bounds, type);
    return node;
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) BoundingBox(org.opengis.geometry.BoundingBox) Node(org.locationtech.geogig.api.Node)

Example 3 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class WorkingTree method insert.

/**
     * Insert a single feature into the working tree and updates the WORK_HEAD ref.
     * 
     * @param parentTreePath path of the parent tree to insert the feature into
     * @param feature the feature to insert
     */
public Node insert(final String parentTreePath, final Feature feature) {
    final FeatureType featureType = feature.getType();
    NodeRef treeRef;
    Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(parentTreePath).call();
    ObjectId metadataId;
    if (typeTreeRef.isPresent()) {
        treeRef = typeTreeRef.get();
        RevFeatureType newFeatureType = RevFeatureTypeImpl.build(featureType);
        metadataId = newFeatureType.getId().equals(treeRef.getMetadataId()) ? ObjectId.NULL : newFeatureType.getId();
        if (!newFeatureType.getId().equals(treeRef.getMetadataId())) {
            indexDatabase.put(newFeatureType);
        }
    } else {
        treeRef = createTypeTree(parentTreePath, featureType);
        // treeRef.getMetadataId();
        metadataId = ObjectId.NULL;
    }
    // ObjectId metadataId = treeRef.getMetadataId();
    final Node node = putInDatabase(feature, metadataId);
    RevTreeBuilder parentTree = context.command(FindOrCreateSubtree.class).setIndex(true).setParent(Suppliers.ofInstance(Optional.of(getTree()))).setChildPath(parentTreePath).call().builder(indexDatabase);
    parentTree.put(node);
    final ObjectId treeMetadataId = treeRef.getMetadataId();
    ObjectId newTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()).setChildPath(parentTreePath).setToIndex(true).setTree(parentTree.build()).setMetadataId(treeMetadataId).call();
    updateWorkHead(newTree);
    final String featurePath = NodeRef.appendChild(parentTreePath, node.getName());
    Optional<NodeRef> featureRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(featurePath).call();
    return featureRef.get().getNode();
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) FeatureType(org.opengis.feature.type.FeatureType) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) FindOrCreateSubtree(org.locationtech.geogig.api.plumbing.FindOrCreateSubtree) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 4 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class RevFeatureTypeSerializationTest method testSerializationWGS84.

@Test
public void testSerializationWGS84() throws Exception {
    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.add("geom", Polygon.class, DefaultGeographicCRS.WGS84);
    ftb.setName("type");
    SimpleFeatureType ftype = ftb.buildFeatureType();
    RevFeatureType revFeatureType = RevFeatureTypeImpl.build(ftype);
    ObjectWriter<RevFeatureType> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    writer.write(revFeatureType, output);
    byte[] data = output.toByteArray();
    assertTrue(data.length > 0);
    ObjectReader<RevFeatureType> reader = factory.createObjectReader(TYPE.FEATURETYPE);
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    RevFeatureType rft = reader.read(revFeatureType.getId(), input);
    assertNotNull(rft);
    FeatureType serializedFeatureType = rft.type();
    assertEquals("EPSG:4326", CRS.toSRS(serializedFeatureType.getCoordinateReferenceSystem()));
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 5 with FeatureType

use of org.opengis.feature.type.FeatureType in project GeoGig by boundlessgeo.

the class OSMHistoryImportTest method test.

@Test
public void test() throws Exception {
    cli.execute("config", "user.name", "Gabriel Roldan");
    cli.execute("config", "user.email", "groldan@boundlessgeo.com");
    cli.execute("osm", "import-history", fakeOsmApiUrl, "--to", "10");
    GeoGIG geogig = cli.getGeogig();
    List<DiffEntry> changes = ImmutableList.copyOf(geogig.command(DiffOp.class).setOldVersion("HEAD~2").setNewVersion("HEAD~1").call());
    assertEquals(1, changes.size());
    DiffEntry entry = changes.get(0);
    assertEquals(ChangeType.MODIFIED, entry.changeType());
    assertEquals("node/20", entry.getOldObject().path());
    assertEquals("node/20", entry.getNewObject().path());
    Optional<RevFeature> oldRevFeature = geogig.command(RevObjectParse.class).setObjectId(entry.getOldObject().objectId()).call(RevFeature.class);
    Optional<RevFeature> newRevFeature = geogig.command(RevObjectParse.class).setObjectId(entry.getNewObject().objectId()).call(RevFeature.class);
    assertTrue(oldRevFeature.isPresent());
    assertTrue(newRevFeature.isPresent());
    Optional<RevFeatureType> type = geogig.command(RevObjectParse.class).setObjectId(entry.getOldObject().getMetadataId()).call(RevFeatureType.class);
    assertTrue(type.isPresent());
    FeatureType featureType = type.get().type();
    CoordinateReferenceSystem expected = CRS.decode("EPSG:4326", true);
    CoordinateReferenceSystem actual = featureType.getCoordinateReferenceSystem();
    assertTrue(actual.toString(), CRS.equalsIgnoreMetadata(expected, actual));
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevFeature(org.locationtech.geogig.api.RevFeature) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Aggregations

FeatureType (org.opengis.feature.type.FeatureType)9 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)8 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 FeatureSource (org.geotools.data.FeatureSource)2 JDBCFeatureSource (org.geotools.jdbc.JDBCFeatureSource)2 Test (org.junit.Test)2 Node (org.locationtech.geogig.api.Node)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 ForwardingFeatureSource (org.locationtech.geogig.api.data.ForwardingFeatureSource)2 ResolveFeatureType (org.locationtech.geogig.api.plumbing.ResolveFeatureType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Point (com.vividsolutions.jts.geom.Point)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1 Query (org.geotools.data.Query)1 DecoratingFeature (org.geotools.feature.DecoratingFeature)1