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;
}
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;
}
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();
}
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()));
}
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));
}
Aggregations