use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class FormatCommonV2 method readBucketBody.
/**
* Reads a bucket body (i.e assumes the head unsigned int "index" has been read already)
*/
private static final Bucket readBucketBody(DataInput in) throws IOException {
ObjectId objectId = readObjectId(in);
final int boundsMask = in.readByte() & 0xFF;
@Nullable final Envelope bounds;
if (BOUNDS_POINT_MASK == boundsMask) {
bounds = readPointBoundingBox(in);
} else if (BOUNDS_BOX2D_MASK == boundsMask) {
bounds = readBoundingBox(in);
} else {
bounds = null;
}
return Bucket.create(objectId, bounds);
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class WorkingTree method putInDatabase.
/**
* Adds a single feature to the staging database.
*
* @param feature the feature to add
* @param metadataId
* @return the Node for the inserted feature
*/
private Node putInDatabase(final Feature feature, final ObjectId metadataId) {
checkNotNull(feature);
checkNotNull(metadataId);
final RevFeature newFeature = RevFeatureBuilder.build(feature);
final ObjectId objectId = newFeature.getId();
final Envelope bounds = (ReferencedEnvelope) feature.getBounds();
final String nodeName = feature.getIdentifier().getID();
indexDatabase.put(newFeature);
Node newObject = Node.create(nodeName, objectId, metadataId, TYPE.FEATURE, bounds);
return newObject;
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class RevTreeBuilder2 method putFeature.
public Node putFeature(final ObjectId id, final String name, @Nullable final BoundingBox bounds, final FeatureType type) {
Envelope bbox;
if (bounds == null) {
bbox = null;
} else if (bounds instanceof Envelope) {
bbox = (Envelope) bounds;
} else {
bbox = new Envelope(bounds.getMinimum(0), bounds.getMaximum(0), bounds.getMinimum(1), bounds.getMaximum(1));
}
RevFeatureType revFeatureType = revFeatureTypes.get(type.getName());
if (null == revFeatureType) {
revFeatureType = RevFeatureTypeImpl.build(type);
revFeatureTypes.put(type.getName(), revFeatureType);
}
ObjectId metadataId = revFeatureType.getId().equals(defaultMetadataId) ? ObjectId.NULL : revFeatureType.getId();
Node node = Node.create(name, id, metadataId, TYPE.FEATURE, bbox);
put(node);
return node;
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class FormatCommonV1 method readBucket.
public static final Bucket readBucket(DataInput in) throws IOException {
final byte[] hash = new byte[20];
in.readFully(hash);
ObjectId objectId = ObjectId.createNoClone(hash);
Envelope bounds = readBBox(in);
return Bucket.create(objectId, bounds);
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class WriteBack method writeBack.
private ObjectId writeBack(RevTreeBuilder ancestor, final String ancestorPath, final RevTree childTree, final String childPath, final ObjectDatabase targetDatabase, final ObjectId metadataId) {
final ObjectId treeId = childTree.getId();
targetDatabase.put(childTree);
final boolean isDirectChild = NodeRef.isDirectChild(ancestorPath, childPath);
if (isDirectChild) {
Envelope treeBounds = null;
if (!metadataId.isNull()) {
// only include bounds for trees with a default feature type
treeBounds = SpatialOps.boundsOf(childTree);
}
String childName = childPath;
Node treeNode = Node.create(childName, treeId, metadataId, TYPE.TREE, treeBounds);
ancestor.put(treeNode);
RevTree newAncestor = ancestor.build();
targetDatabase.put(newAncestor);
return newAncestor.getId();
}
final String parentPath = NodeRef.parentPath(childPath);
Optional<NodeRef> parentRef = getTreeChild(ancestor, parentPath);
RevTreeBuilder parentBuilder;
ObjectId parentMetadataId = ObjectId.NULL;
if (parentRef.isPresent()) {
ObjectId parentId = parentRef.get().objectId();
parentMetadataId = parentRef.get().getMetadataId();
parentBuilder = getTree(parentId, targetDatabase).builder(targetDatabase);
} else {
parentBuilder = RevTree.EMPTY.builder(targetDatabase);
}
String childName = NodeRef.nodeFromPath(childPath);
Envelope treeBounds = null;
if (!metadataId.isNull()) {
// only include bounds for trees with a default feature type
treeBounds = SpatialOps.boundsOf(childTree);
}
Node treeNode = Node.create(childName, treeId, metadataId, TYPE.TREE, treeBounds);
parentBuilder.put(treeNode);
RevTree parent = parentBuilder.build();
return writeBack(ancestor, ancestorPath, parent, parentPath, targetDatabase, parentMetadataId);
}
Aggregations