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