Search in sources :

Example 1 with EntityFinder

use of de.topobyte.osm4j.core.resolve.EntityFinder in project osm4j-geometry by topobyte.

the class LineworkBuilder method build.

public LineworkBuilderResult build(OsmRelation relation, OsmEntityProvider provider) throws EntityNotFoundException {
    EntityNotFoundStrategy enfs = Util.strategy(missingEntitiesStrategy, log, logLevel);
    EntityFinder finder = EntityFinders.create(provider, enfs);
    Set<OsmNode> nodes = new HashSet<>();
    Set<OsmWay> ways = new HashSet<>();
    try {
        finder.findMemberNodesAndWays(relation, nodes, ways);
    } catch (EntityNotFoundException e) {
        switch(missingEntitiesStrategy) {
            default:
            case THROW_EXCEPTION:
                throw (e);
            case BUILD_EMPTY:
                return new LineworkBuilderResult();
            case BUILD_PARTIAL:
                // case
                break;
        }
    }
    return build(nodes, ways, provider);
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException) EntityNotFoundStrategy(de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy) EntityFinder(de.topobyte.osm4j.core.resolve.EntityFinder) HashSet(java.util.HashSet)

Example 2 with EntityFinder

use of de.topobyte.osm4j.core.resolve.EntityFinder in project osm4j-geometry by topobyte.

the class RegionBuilder method build.

/**
 * Build a MultiPolygon from a Relation.
 *
 * @param relation
 *            a relation to construct the region for.
 * @return the constructed MultiPolygon.
 * @throws EntityNotFoundException
 *             when a required entity cannot be obtained.
 */
public RegionBuilderResult build(OsmRelation relation, OsmEntityProvider resolver) throws EntityNotFoundException {
    EntityNotFoundStrategy enfs = Util.strategy(missingEntitiesStrategy, log, logLevel);
    logger.debug("building region id:" + relation.getId());
    Set<OsmRelation> relations = new HashSet<>();
    MultiSet<OsmWay> ways = new HashMultiSet<>();
    EntityFinder finder = EntityFinders.create(resolver, enfs);
    relations.add(relation);
    finder.findMemberRelationsRecursively(relation, relations);
    finder.findMemberWays(relations, ways);
    Set<OsmNode> nodes = new HashSet<>();
    if (includePuntal) {
        finder.findMemberNodes(relations, nodes);
    }
    return build(ways, resolver, nodes);
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) HashMultiSet(de.topobyte.adt.multicollections.HashMultiSet) EntityNotFoundStrategy(de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy) EntityFinder(de.topobyte.osm4j.core.resolve.EntityFinder) HashSet(java.util.HashSet)

Example 3 with EntityFinder

use of de.topobyte.osm4j.core.resolve.EntityFinder in project osm4j-geometry by topobyte.

the class LineworkBuilder method build.

public LineworkBuilderResult build(Collection<OsmRelation> relations, OsmEntityProvider provider) throws EntityNotFoundException {
    EntityNotFoundStrategy enfs = Util.strategy(missingEntitiesStrategy, log, logLevel);
    EntityFinder finder = EntityFinders.create(provider, enfs);
    Set<OsmNode> nodes = new HashSet<>();
    Set<OsmWay> ways = new HashSet<>();
    try {
        finder.findMemberNodesAndWays(relations, nodes, ways);
    } catch (EntityNotFoundException e) {
        switch(missingEntitiesStrategy) {
            default:
            case THROW_EXCEPTION:
                throw (e);
            case BUILD_EMPTY:
                return new LineworkBuilderResult();
            case BUILD_PARTIAL:
                // case
                break;
        }
    }
    return build(nodes, ways, provider);
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException) EntityNotFoundStrategy(de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy) EntityFinder(de.topobyte.osm4j.core.resolve.EntityFinder) HashSet(java.util.HashSet)

Aggregations

OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)3 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)3 EntityFinder (de.topobyte.osm4j.core.resolve.EntityFinder)3 EntityNotFoundStrategy (de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy)3 HashSet (java.util.HashSet)3 EntityNotFoundException (de.topobyte.osm4j.core.resolve.EntityNotFoundException)2 HashMultiSet (de.topobyte.adt.multicollections.HashMultiSet)1 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)1