Search in sources :

Example 16 with OsmNode

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

the class WayBuilder method buildThrowExceptionIfNodeMissing.

public WayBuilderResult buildThrowExceptionIfNodeMissing(OsmWay way, OsmEntityProvider resolver) throws EntityNotFoundException {
    WayBuilderResult result = new WayBuilderResult();
    int numNodes = way.getNumberOfNodes();
    if (numNodes == 0) {
        return result;
    }
    if (numNodes == 1) {
        if (!includePuntal) {
            return result;
        } else {
            OsmNode node = resolver.getNode(way.getNodeId(0));
            result.getCoordinates().add(nodeBuilder.buildCoordinate(node));
        }
    }
    CoordinateSequence cs = factory.getCoordinateSequenceFactory().create(numNodes, 2);
    for (int i = 0; i < numNodes; i++) {
        OsmNode node = resolver.getNode(way.getNodeId(i));
        cs.setOrdinate(i, 0, node.getLongitude());
        cs.setOrdinate(i, 1, node.getLatitude());
    }
    createLine(result, cs, OsmModelUtil.isClosed(way));
    return result;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode)

Example 17 with OsmNode

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

the class RelationUtil method checkRings.

/**
 * For each ring in this collection of rings, check whether it is closed. If
 * not, print some status information.
 *
 * @param missingEntitiesStrategy
 */
public static void checkRings(Collection<ChainOfWays> rings, OsmEntityProvider resolver, MissingEntitiesStrategy missingEntitiesStrategy) throws EntityNotFoundException {
    for (ChainOfWays ring : rings) {
        if (ring.isClosed()) {
            continue;
        }
        List<WaySegment> segments = ring.getSegments();
        int len = 0;
        for (WaySegment rs : segments) {
            len += rs.getWay().getNumberOfNodes();
        }
        WaySegment seg0 = segments.get(0);
        WaySegment segN = segments.get(segments.size() - 1);
        long nodeId1 = seg0.getNodeId(0);
        long nodeIdN = segN.getNodeId(segN.getNumberOfNodes() - 1);
        try {
            OsmNode node1 = resolver.getNode(nodeId1);
            OsmNode nodeN = resolver.getNode(nodeIdN);
            logger.debug("we have an unclosed ring of size " + len);
            logger.debug(String.format("start/end: %f,%f %f,%f", node1.getLongitude(), node1.getLatitude(), nodeN.getLongitude(), nodeN.getLatitude()));
        } catch (EntityNotFoundException e) {
            switch(missingEntitiesStrategy) {
                case BUILD_PARTIAL:
                    continue;
                default:
                case BUILD_EMPTY:
                case THROW_EXCEPTION:
                    throw (e);
            }
        }
    }
}
Also used : OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException)

Example 18 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(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 19 with OsmNode

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

the class TestNodeIterator method test.

@Test
public void test() throws IOException {
    InMemoryListDataSet data = ListDataSetLoader.read(createInput().createIterator(true, true), true, true, true);
    OsmIteratorInput input = createInput().createIterator(true, true);
    NodeIterator nodeIterator = new NodeIterator(input.getIterator());
    List<OsmNode> nodes = Lists.newArrayList(nodeIterator.iterator());
    input.close();
    assertEquals(data.getNodes().size(), nodes.size());
    for (int i = 0; i < nodes.size(); i++) {
        OsmNode a = nodes.get(i);
        OsmNode b = data.getNodes().get(i);
        assertTrue(EqualityUtil.equals(a, b));
    }
}
Also used : OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) OsmIteratorInput(de.topobyte.osm4j.core.access.OsmIteratorInput) InMemoryListDataSet(de.topobyte.osm4j.core.dataset.InMemoryListDataSet) Test(org.junit.Test)

Example 20 with OsmNode

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

the class EntityFinderLogMissing method findNodes.

@Override
public List<OsmNode> findNodes(TLongCollection ids) throws EntityNotFoundException {
    List<OsmNode> nodes = new ArrayList<>();
    TLongIterator idIterator = ids.iterator();
    while (idIterator.hasNext()) {
        long id = idIterator.next();
        try {
            nodes.add(entityProvider.getNode(id));
        } catch (EntityNotFoundException e) {
            logNodeNotFound(id);
        }
    }
    return nodes;
}
Also used : OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) TLongIterator(com.slimjars.dist.gnu.trove.iterator.TLongIterator)

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