use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-geometry by topobyte.
the class RelationUtil method buildRings.
/**
* Given a set of ways and their head's and tail's in the wayTailMap,
* construct valid rings by combining ways with same tail-ids.
*/
public static List<ChainOfWays> buildRings(MultiSet<OsmWay> ways, CountingMultiValMap<Long, OsmWay> wayTailMap) {
List<ChainOfWays> rings = new ArrayList<>();
while (ways.keySet().size() > 0) {
// Pick a way as part of a new ring
OsmWay way = ways.keySet().iterator().next();
ChainOfWays ring = new ChainOfWays(way);
rings.add(ring);
// Remove it from the set of ways...
ways.remove(way);
// ...and from the tail map.
long id0 = way.getNodeId(0);
long idN = way.getNodeId(way.getNumberOfNodes() - 1);
wayTailMap.remove(id0, way);
wayTailMap.remove(idN, way);
// Try to assemble a ring for the way
while (!ring.isClosed()) {
long last = ring.getLast();
Set<OsmWay> waySet = wayTailMap.getForKey(last);
boolean accept = false;
Iterator<OsmWay> iter = waySet.iterator();
OsmWay take = null;
while (iter.hasNext()) {
take = iter.next();
if (ring.getWaySet().contains(take)) {
// do not allow the same way to be included twice.
continue;
}
accept = true;
break;
}
if (!accept) {
// System.out.println(ring.segments.get(ring.segments.size()-1).getWay().getId());
break;
}
if (take == null) {
// can't be null, but avoid warning.
break;
}
// Extend the current ring with the found way..
ring.addWay(take);
// And remove it from the set of ways...
ways.remove(take);
// ...and from the tail map.
long tid0 = take.getNodeId(0);
long tidN = take.getNodeId(take.getNumberOfNodes() - 1);
wayTailMap.remove(tid0, take);
wayTailMap.remove(tidN, take);
}
}
return rings;
}
use of de.topobyte.osm4j.core.model.iface.OsmWay 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);
}
use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-core by topobyte.
the class TestDataSetGetters method getWaySuccessful.
@Test
public void getWaySuccessful() throws EntityNotFoundException {
OsmWay way = data.getWay(1);
assertEquals(way.getId(), 1);
}
use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-core by topobyte.
the class EntityFinderIgnoreMissing method findWays.
@Override
public List<OsmWay> findWays(TLongCollection ids) throws EntityNotFoundException {
List<OsmWay> ways = new ArrayList<>();
TLongIterator idIterator = ids.iterator();
while (idIterator.hasNext()) {
try {
ways.add(entityProvider.getWay(idIterator.next()));
} catch (EntityNotFoundException e) {
// ignore silently
}
}
return ways;
}
use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-core by topobyte.
the class EntityFinderThrowMissing method findWays.
@Override
public List<OsmWay> findWays(TLongCollection ids) throws EntityNotFoundException {
List<OsmWay> ways = new ArrayList<>();
TLongIterator idIterator = ids.iterator();
while (idIterator.hasNext()) {
ways.add(entityProvider.getWay(idIterator.next()));
}
return ways;
}
Aggregations