use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-geometry by topobyte.
the class RegionBuilder method build.
/**
* Build a MultiPolygon from a Set of Ways.
*
* @param ways
* the ways to use for geometry construction.
* @return the constructed MultiPolygon.
* @throws EntityNotFoundException
* when a required entity cannot be obtained.
*/
public RegionBuilderResult build(MultiSet<OsmWay> ways, OsmEntityProvider resolver, Set<OsmNode> nodes) throws EntityNotFoundException {
RegionBuilderResult result = new RegionBuilderResult();
logger.debug("Have " + ways.keySet().size() + " ways");
// Only keep ways with 2 or more nodes. Also don't keep ways with just 2
// times the same node.
List<OsmWay> invalidWays = new ArrayList<>();
for (OsmWay way : ways.keySet()) {
int numNodes = way.getNumberOfNodes();
if (numNodes == 0 || numNodes == 1) {
invalidWays.add(way);
} else if (numNodes == 2 && OsmModelUtil.isClosed(way)) {
invalidWays.add(way);
}
}
ways.removeAllOccurences(invalidWays);
logger.debug("Removed " + invalidWays.size() + " invalid ways");
CountingMultiValMap<Long, OsmWay> wayTailMap = RelationUtil.buildWayTailMap(ways);
List<ChainOfWays> chains = RelationUtil.buildRings(ways, wayTailMap);
List<ChainOfNodes> rings = new ArrayList<>();
List<ChainOfNodes> nonRings = new ArrayList<>();
RelationUtil.convertToSegmentChainsAndResolveNodeIntersections(chains, rings, nonRings);
try {
RelationUtil.checkRings(chains, resolver, missingEntitiesStrategy);
} catch (EntityNotFoundException e) {
switch(missingEntitiesStrategy) {
case BUILD_PARTIAL:
// exception with BUILD_PARTIAL
break;
case BUILD_EMPTY:
return new RegionBuilderResult();
default:
case THROW_EXCEPTION:
throw (e);
}
}
// This could be used to close non-closed chains
// RelationUtil.closeUnclosedRingWithStraightLine(rings);
List<LinearRing> linearRings = new ArrayList<>();
convert(rings, nonRings, resolver, result.getCoordinates(), result.getLineStrings(), linearRings);
Set<LinearRing> validRings = new HashSet<>();
for (LinearRing r : linearRings) {
Set<LinearRing> repaired = SelfIntersectionUtil.repair(r);
for (LinearRing ring : repaired) {
validRings.add(ring);
}
}
MultiPolygon mp = PolygonHelper.multipolygonFromRings(validRings, false);
result.setMultiPolygon(mp);
if (includePuntal) {
GeometryUtil.buildNodes(nodeBuilder, nodes, result.getCoordinates());
}
return result;
}
use of de.topobyte.osm4j.core.model.iface.OsmWay 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);
}
use of de.topobyte.osm4j.core.model.iface.OsmWay 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);
}
use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-geometry by topobyte.
the class LineworkBuilder method build.
public LineworkBuilderResult build(Collection<OsmNode> nodes, Collection<OsmWay> ways, OsmEntityProvider provider) throws EntityNotFoundException {
LineworkBuilderResult result = new LineworkBuilderResult();
GeometryUtil.buildNodes(nodeBuilder, nodes, result.getCoordinates());
for (OsmWay way : ways) {
WayBuilderResult wbr = wayBuilder.build(way, provider);
result.getCoordinates().addAll(wbr.getCoordinates());
result.getLineStrings().addAll(wbr.getLineStrings());
if (wbr.getLinearRing() != null) {
result.getLineStrings().add(wbr.getLinearRing());
}
}
return result;
}
Aggregations