Search in sources :

Example 11 with OsmNode

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

the class EntityFinderIgnoreMissing method findNodes.

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

Example 12 with OsmNode

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

the class EntityFinderThrowMissing method findNodes.

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

Example 13 with OsmNode

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

the class ImplUtil method clone.

public static Node clone(OsmNode node) {
    List<? extends OsmTag> tags = cloneTags(node);
    OsmMetadata metadata = cloneMetadata(node);
    return new Node(node.getId(), node.getLongitude(), node.getLatitude(), tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) Node(de.topobyte.osm4j.core.model.impl.Node) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode)

Example 14 with OsmNode

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

the class WayBuilder method buildReturnEmptyIfNodeMissing.

public WayBuilderResult buildReturnEmptyIfNodeMissing(OsmWay way, OsmEntityProvider resolver) {
    WayBuilderResult result = new WayBuilderResult();
    int numNodes = way.getNumberOfNodes();
    if (numNodes == 0) {
        return result;
    }
    if (numNodes == 1) {
        if (!includePuntal) {
            return result;
        } else {
            try {
                OsmNode node = resolver.getNode(way.getNodeId(0));
                result.getCoordinates().add(nodeBuilder.buildCoordinate(node));
            } catch (EntityNotFoundException e) {
                return result;
            }
        }
    }
    CoordinateSequence cs = factory.getCoordinateSequenceFactory().create(numNodes, 2);
    for (int i = 0; i < way.getNumberOfNodes(); i++) {
        OsmNode node;
        try {
            node = resolver.getNode(way.getNodeId(i));
        } catch (EntityNotFoundException e) {
            result.clear();
            return result;
        }
        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) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException)

Example 15 with OsmNode

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

the class WayBuilder method buildOmitVertexIfNodeMissing.

public WayBuilderResult buildOmitVertexIfNodeMissing(OsmWay way, OsmEntityProvider resolver) {
    WayBuilderResult result = new WayBuilderResult();
    // 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;
    List<Coordinate> coords = new ArrayList<>();
    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;
            }
            continue;
        }
        coords.add(new Coordinate(node.getLongitude(), node.getLatitude()));
    }
    if (coords.size() == 0) {
        return result;
    }
    if (coords.size() == 1) {
        if (!includePuntal) {
            return result;
        } else {
            result.getCoordinates().add(coords.get(0));
            return result;
        }
    }
    // the way by replicating the first found coordinate at the end.
    if (closed && firstMissing && coords.size() > 2) {
        coords.add(coords.get(0));
    }
    CoordinateSequence cs = factory.getCoordinateSequenceFactory().create(coords.toArray(new Coordinate[0]));
    createLine(result, cs, closed);
    return result;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Coordinate(com.vividsolutions.jts.geom.Coordinate) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException)

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