use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class GeogigSimpleFeature method getBounds.
@Override
public BoundingBox getBounds() {
CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem();
Envelope bounds = ReferencedEnvelope.create(crs);
if (node == null) {
Optional<Object> o;
List<Optional<Object>> values = getValues();
for (int i = 0; i < values.size(); i++) {
o = values.get(i);
if (o.isPresent() && o.get() instanceof Geometry) {
Geometry g = (Geometry) o.get();
// crs as the feature type
if (bounds.isNull()) {
bounds.init(JTS.bounds(g, crs));
} else {
bounds.expandToInclude(JTS.bounds(g, crs));
}
}
}
} else {
node.expand(bounds);
}
return (BoundingBox) bounds;
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class GeogigFeatureReader method getQueryBounds.
private ReferencedEnvelope getQueryBounds(Filter filterInNativeCrs, NodeRef typeTreeRef) {
CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem();
if (crs == null) {
crs = DefaultEngineeringCRS.GENERIC_2D;
}
ReferencedEnvelope queryBounds = new ReferencedEnvelope(crs);
@SuppressWarnings("unchecked") List<ReferencedEnvelope> bounds = (List<ReferencedEnvelope>) filterInNativeCrs.accept(new ExtractBounds(crs), null);
if (bounds != null && !bounds.isEmpty()) {
expandToInclude(queryBounds, bounds);
ReferencedEnvelope fullBounds;
fullBounds = new ReferencedEnvelope(crs);
typeTreeRef.expand(fullBounds);
Envelope clipped = fullBounds.intersection(queryBounds);
LOGGER.trace("query bounds: {}", queryBounds);
queryBounds = new ReferencedEnvelope(crs);
queryBounds.expandToInclude(clipped);
LOGGER.trace("clipped query bounds: {}", queryBounds);
if (queryBounds.equals(fullBounds)) {
queryBounds.setToNull();
}
}
return queryBounds;
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class FormatCommonV1 method readNode.
public static Node readNode(DataInput in) throws IOException {
final String name = in.readUTF();
final byte[] objectId = new byte[20];
in.readFully(objectId);
final byte[] metadataId = new byte[20];
in.readFully(metadataId);
final RevObject.TYPE contentType = RevObject.TYPE.valueOf(in.readByte());
final Envelope bbox = readBBox(in);
final Node node;
node = Node.create(name, ObjectId.createNoClone(objectId), ObjectId.createNoClone(metadataId), contentType, bbox);
return node;
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class FormatCommonV2 method writeTree.
public static void writeTree(RevTree tree, DataOutput data) throws IOException {
writeUnsignedVarLong(tree.size(), data);
writeUnsignedVarInt(tree.numTrees(), data);
Envelope envBuff = new Envelope();
final int nFeatures = tree.features().isPresent() ? tree.features().get().size() : 0;
writeUnsignedVarInt(nFeatures, data);
if (nFeatures > 0) {
for (Node feature : tree.features().get()) {
writeNode(feature, data, envBuff);
}
}
final int nTrees = tree.trees().isPresent() ? tree.trees().get().size() : 0;
writeUnsignedVarInt(nTrees, data);
if (nTrees > 0) {
for (Node subTree : tree.trees().get()) {
writeNode(subTree, data, envBuff);
}
}
final int nBuckets = tree.buckets().isPresent() ? tree.buckets().get().size() : 0;
writeUnsignedVarInt(nBuckets, data);
if (tree.buckets().isPresent()) {
ImmutableSortedMap<Integer, Bucket> buckets = tree.buckets().get();
for (Map.Entry<Integer, Bucket> bucket : buckets.entrySet()) {
writeBucket(bucket.getKey(), bucket.getValue(), data, envBuff);
}
}
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class PreOrderDiffWalk method walk.
/**
* Walk up the differences between the two trees and emit events to the {@code consumer}.
* <p>
* If the two root trees are not equal, an initial call to {@link Consumer#tree(Node, Node)}
* will be made where the nodes will have {@link NodeRef#ROOT the root name} (i.e. empty
* string), and provided the consumer indicates to continue with the traversal, further calls to
* {@link Consumer#feature}, {@link Consumer#tree}, and/or {@link Consumer#bucket} will be made
* as changes between the two trees are found.
* <p>
* At any time, if {@link Consumer#tree} or {@link Consumer#bucket} returns {@code false}, that
* pair of trees won't be further evaluated and the traversal continues with their siblings or
* parents if there are no more siblings.
* <p>
* Note the {@code consumer} is only notified of nodes or buckets that differ, using
* {@code null} of either the left of right argument to indicate there's no matching object at
* the left or right side of the comparison. Left side nulls indicate a new object, right side
* nulls a deleted one. None of the {@code Consumer} method is ever called with equal left and
* right arguments.
*
* @param consumer the callback object that gets notified of changes between the two trees and
* can abort the walk for whole subtrees.
*/
public final void walk(Consumer consumer) {
if (left.equals(right)) {
return;
}
// start by asking the consumer if go on with the walk at all with the
// root nodes
Envelope lbounds = SpatialOps.boundsOf(left);
Node lnode = Node.create(NodeRef.ROOT, left.getId(), ObjectId.NULL, TYPE.TREE, lbounds);
Envelope rbounds = SpatialOps.boundsOf(right);
Node rnode = Node.create(NodeRef.ROOT, right.getId(), ObjectId.NULL, TYPE.TREE, rbounds);
if (consumer.tree(lnode, rnode)) {
traverseTree(consumer, left, right, 0);
}
consumer.endTree(lnode, rnode);
}
Aggregations