Search in sources :

Example 6 with EntityNotFoundException

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

the class WayBuilder method buildSplitIfNodeMissing.

public WayBuilderResult buildSplitIfNodeMissing(OsmWay way, OsmEntityProvider resolver) {
    // Test if the way is closed, i.e. first node id == last node id
    boolean closed = OsmModelUtil.isClosed(way);
    // Remember if the first node is missing, so that we can handle closed
    // ways appropriately
    boolean firstMissing = false;
    CoordinateSequencesBuilder builder = new CoordinateSequencesBuilder();
    builder.beginNewSequence();
    for (int i = 0; i < way.getNumberOfNodes(); i++) {
        OsmNode node;
        try {
            node = resolver.getNode(way.getNodeId(i));
        } catch (EntityNotFoundException e) {
            if (log) {
                logMissingNode(way.getNodeId(i));
            }
            if (i == 0) {
                firstMissing = true;
            }
            builder.beginNewSequence();
            continue;
        }
        builder.add(new Coordinate(node.getLongitude(), node.getLatitude()));
    }
    builder.finishSequence();
    return builder.createWayBuilderResult(factory, includePuntal, closed, firstMissing);
}
Also used : OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) Coordinate(com.vividsolutions.jts.geom.Coordinate) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException)

Example 7 with EntityNotFoundException

use of de.topobyte.osm4j.core.resolve.EntityNotFoundException 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

EntityNotFoundException (de.topobyte.osm4j.core.resolve.EntityNotFoundException)7 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)6 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)3 HashSet (java.util.HashSet)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)2 EntityFinder (de.topobyte.osm4j.core.resolve.EntityFinder)2 EntityNotFoundStrategy (de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy)2 ArrayList (java.util.ArrayList)2 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)1 ChainOfNodes (de.topobyte.osm4j.geometry.relation.ChainOfNodes)1 ChainOfWays (de.topobyte.osm4j.geometry.relation.ChainOfWays)1