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;
}
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);
}
}
}
}
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);
}
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));
}
}
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;
}
Aggregations