use of javax.management.relation.Relation in project GeoGig by boundlessgeo.
the class OSMHistoryImport method parseGeometry.
/**
* @param primitive
* @param thisChangePointCache
* @return
*/
private Geometry parseGeometry(GeoGIG geogig, Primitive primitive, Map<Long, Coordinate> thisChangePointCache) {
if (primitive instanceof Relation) {
return null;
}
if (primitive instanceof Node) {
Optional<Point> location = ((Node) primitive).getLocation();
return location.orNull();
}
final Way way = (Way) primitive;
final ImmutableList<Long> nodes = way.getNodes();
StagingArea index = geogig.getRepository().index();
FeatureBuilder featureBuilder = new FeatureBuilder(NODE_REV_TYPE);
List<Coordinate> coordinates = Lists.newArrayList(nodes.size());
FindTreeChild findTreeChild = geogig.command(FindTreeChild.class);
findTreeChild.setIndex(true);
ObjectId rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(Ref.HEAD).call().get();
if (!rootTreeId.isNull()) {
RevTree headTree = geogig.command(RevObjectParse.class).setObjectId(rootTreeId).call(RevTree.class).get();
findTreeChild.setParent(headTree);
}
for (Long nodeId : nodes) {
Coordinate coord = thisChangePointCache.get(nodeId);
if (coord == null) {
String fid = String.valueOf(nodeId);
String path = NodeRef.appendChild(NODE_TYPE_NAME, fid);
Optional<org.locationtech.geogig.api.Node> ref = index.findStaged(path);
if (!ref.isPresent()) {
Optional<NodeRef> nodeRef = findTreeChild.setChildPath(path).call();
if (nodeRef.isPresent()) {
ref = Optional.of(nodeRef.get().getNode());
} else {
ref = Optional.absent();
}
}
if (ref.isPresent()) {
org.locationtech.geogig.api.Node nodeRef = ref.get();
RevFeature revFeature = index.getDatabase().getFeature(nodeRef.getObjectId());
String id = NodeRef.nodeFromPath(nodeRef.getName());
Feature feature = featureBuilder.build(id, revFeature);
Point p = (Point) ((SimpleFeature) feature).getAttribute("location");
if (p != null) {
coord = p.getCoordinate();
thisChangePointCache.put(Long.valueOf(nodeId), coord);
}
}
}
if (coord != null) {
coordinates.add(coord);
}
}
if (coordinates.size() < 2) {
return null;
}
return GEOMF.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
Aggregations