Search in sources :

Example 1 with Node

use of org.locationtech.geogig.osm.internal.history.Node in project GeoGig by boundlessgeo.

the class OSMHistoryImport method toFeature.

private static SimpleFeature toFeature(Primitive feature, Geometry geom) {
    SimpleFeatureType ft = feature instanceof Node ? nodeType() : wayType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
    // "visible:Boolean,version:Int,timestamp:long,[location:Point | way:LineString];
    builder.set("visible", Boolean.valueOf(feature.isVisible()));
    builder.set("version", Integer.valueOf(feature.getVersion()));
    builder.set("timestamp", Long.valueOf(feature.getTimestamp()));
    builder.set("changeset", Long.valueOf(feature.getChangesetId()));
    String tags = buildTagsString(feature.getTags());
    builder.set("tags", tags);
    String user = feature.getUserName() + ":" + feature.getUserId();
    builder.set("user", user);
    if (feature instanceof Node) {
        builder.set("location", geom);
    } else if (feature instanceof Way) {
        builder.set("way", geom);
        String nodes = buildNodesString(((Way) feature).getNodes());
        builder.set("nodes", nodes);
    } else {
        throw new IllegalArgumentException();
    }
    String fid = String.valueOf(feature.getId());
    SimpleFeature simpleFeature = builder.buildFeature(fid);
    return simpleFeature;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Node(org.locationtech.geogig.osm.internal.history.Node) Way(org.locationtech.geogig.osm.internal.history.Way) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 2 with Node

use of org.locationtech.geogig.osm.internal.history.Node 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()]));
}
Also used : SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) Node(org.locationtech.geogig.osm.internal.history.Node) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) Way(org.locationtech.geogig.osm.internal.history.Way) NodeRef(org.locationtech.geogig.api.NodeRef) Relation(javax.management.relation.Relation) ResolveTreeish(org.locationtech.geogig.api.plumbing.ResolveTreeish) RevFeature(org.locationtech.geogig.api.RevFeature) ObjectId(org.locationtech.geogig.api.ObjectId) StagingArea(org.locationtech.geogig.repository.StagingArea) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Point(com.vividsolutions.jts.geom.Point) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 Node (org.locationtech.geogig.osm.internal.history.Node)2 Way (org.locationtech.geogig.osm.internal.history.Way)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Point (com.vividsolutions.jts.geom.Point)1 Relation (javax.management.relation.Relation)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 RevTree (org.locationtech.geogig.api.RevTree)1 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)1 ResolveTreeish (org.locationtech.geogig.api.plumbing.ResolveTreeish)1 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)1 StagingArea (org.locationtech.geogig.repository.StagingArea)1 Feature (org.opengis.feature.Feature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1