use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-core by topobyte.
the class ImplUtil method clone.
public static Relation clone(OsmRelation relation) {
List<? extends OsmTag> tags = cloneTags(relation);
OsmMetadata metadata = cloneMetadata(relation);
List<RelationMember> members = new ArrayList<>(relation.getNumberOfMembers());
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
OsmRelationMember member = relation.getMember(i);
members.add(new RelationMember(member.getId(), member.getType(), member.getRole()));
}
return new Relation(relation.getId(), members, tags, metadata);
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-geometry by topobyte.
the class TestBuildLinework method main.
public static void main(String[] args) throws MalformedURLException, IOException, ParserConfigurationException, SAXException, EntityNotFoundException {
if (args.length == 0) {
System.out.println("Please specify an input file");
usage();
}
if (args.length != 1) {
System.out.println("Please specify only one input file");
usage();
}
InputStream input = new FileInputStream(args[0]);
OsmIterator iterator = new TboIterator(input, true, true);
InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);
TLongObjectMap<OsmRelation> relations = data.getRelations();
if (relations.isEmpty()) {
logger.warn("No relation found");
return;
}
LineworkBuilder lineworkBuilder = new LineworkBuilder();
lineworkBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
lineworkBuilder.setMissingWayNodeStrategy(MissingWayNodeStrategy.SPLIT_POLYLINE);
RegionBuilder regionBuilder = new RegionBuilder();
regionBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
long[] ids = relations.keys();
Arrays.sort(ids);
for (long id : ids) {
OsmRelation relation = relations.get(id);
logger.info("Relation " + relation.getId());
lineworkBuilder.build(relation, data);
regionBuilder.build(relation, data);
}
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-geometry by topobyte.
the class TestBuildPolygon method main.
public static void main(String[] args) throws MalformedURLException, IOException, ParserConfigurationException, SAXException, EntityNotFoundException {
String query = "http://overpass-api.de/api/interpreter?data=(rel(8638);>;);out;";
// Open a stream
InputStream input = new URL(query).openStream();
OsmIterator iterator = new OsmXmlIterator(input, false);
InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);
TLongObjectMap<OsmRelation> relations = data.getRelations();
if (relations.isEmpty()) {
System.out.println("No relation found");
return;
}
TLongObjectIterator<OsmRelation> ri = relations.iterator();
ri.advance();
OsmRelation relation = ri.value();
File outputDir = new File("/tmp");
String filename = String.format("relation-%d.wkt", relation.getId());
File file = new File(outputDir, filename);
GeometryBuilder geometryBuilder = new GeometryBuilder();
geometryBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
geometryBuilder.setMissingWayNodeStrategy(MissingWayNodeStrategy.OMIT_VERTEX_FROM_POLYLINE);
Geometry polygon = geometryBuilder.build(relation, data);
WKTWriter writer = new WKTWriter();
FileWriter fileWriter = new FileWriter(file);
writer.write(polygon, fileWriter);
fileWriter.close();
System.out.println("Successfully created WKT representation");
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation 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.OsmRelation in project osm4j-pbf by topobyte.
the class PbfWriter method serializeRelations.
private Osmformat.PrimitiveGroup serializeRelations(Collection<OsmRelation> relations) {
Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
for (OsmRelation relation : relations) {
Osmformat.Relation.Builder bi = Osmformat.Relation.newBuilder();
bi.setId(relation.getId());
long lastid = 0;
for (int k = 0; k < relation.getNumberOfMembers(); k++) {
OsmRelationMember j = relation.getMember(k);
long id = j.getId();
bi.addMemids(id - lastid);
lastid = id;
EntityType t = j.getType();
Osmformat.Relation.MemberType type = getType(t);
bi.addTypes(type);
bi.addRolesSid(stringTable.getIndex(j.getRole()));
}
for (int k = 0; k < relation.getNumberOfTags(); k++) {
OsmTag t = relation.getTag(k);
bi.addKeys(stringTable.getIndex(t.getKey()));
bi.addVals(stringTable.getIndex(t.getValue()));
}
if (writeMetadata && relation.getMetadata() != null) {
bi.setInfo(serializeMetadata(relation));
}
builder.addRelations(bi);
}
return builder.build();
}
Aggregations