Search in sources :

Example 21 with OsmNode

use of de.topobyte.osm4j.core.model.iface.OsmNode in project osm4j-core by topobyte.

the class TestDataSetGetters method getNodeSuccessful.

@Test
public void getNodeSuccessful() throws EntityNotFoundException {
    OsmNode node = data.getNode(1);
    assertEquals(node.getId(), 1);
}
Also used : OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) Test(org.junit.Test)

Example 22 with OsmNode

use of de.topobyte.osm4j.core.model.iface.OsmNode in project osm4j-geometry by topobyte.

the class ChainOfWays method toCoordinateSequence.

private CoordinateSequence toCoordinateSequence(OsmEntityProvider resolver) throws EntityNotFoundException {
    CoordinateSequenceFactory csf = factory.getCoordinateSequenceFactory();
    int len = getLength();
    CoordinateSequence points = csf.create(len, 2);
    int n = 0;
    for (int i = 0; i < segments.size(); i++) {
        WaySegment segment = segments.get(i);
        OsmWay way = segment.getWay();
        for (int k = 0; k < way.getNumberOfNodes(); k++) {
            if (k > 0 || i == 0) {
                OsmNode node = resolver.getNode(segment.getNodeId(k));
                points.setOrdinate(n, 0, node.getLongitude());
                points.setOrdinate(n, 1, node.getLatitude());
                n++;
            }
        }
    }
    return points;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory)

Example 23 with OsmNode

use of de.topobyte.osm4j.core.model.iface.OsmNode 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 24 with OsmNode

use of de.topobyte.osm4j.core.model.iface.OsmNode 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 25 with OsmNode

use of de.topobyte.osm4j.core.model.iface.OsmNode 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)25 OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)10 ArrayList (java.util.ArrayList)10 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)7 Node (de.topobyte.osm4j.core.model.impl.Node)7 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)6 EntityNotFoundException (de.topobyte.osm4j.core.resolve.EntityNotFoundException)6 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)4 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)4 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)4 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)4 Relation (de.topobyte.osm4j.core.model.impl.Relation)4 Way (de.topobyte.osm4j.core.model.impl.Way)4 IOException (java.io.IOException)4 TLongIterator (com.slimjars.dist.gnu.trove.iterator.TLongIterator)3 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)3 EntityFinder (de.topobyte.osm4j.core.resolve.EntityFinder)3 EntityNotFoundStrategy (de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy)3 HashSet (java.util.HashSet)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2