use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-core by topobyte.
the class MapDataSetLoader method read.
public static InMemoryMapDataSet read(OsmIterator iterator, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
TLongObjectMap<OsmWay> ways = dataSet.getWays();
TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
if (iterator.hasBounds()) {
dataSet.setBounds(iterator.getBounds());
}
while (iterator.hasNext()) {
EntityContainer container = iterator.next();
switch(container.getType()) {
case Node:
OsmNode node = (OsmNode) container.getEntity();
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.put(node.getId(), node);
break;
case Way:
OsmWay way = (OsmWay) container.getEntity();
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.put(way.getId(), way);
break;
case Relation:
OsmRelation relation = (OsmRelation) container.getEntity();
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.put(relation.getId(), relation);
break;
}
}
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-core by topobyte.
the class MapDataSetLoader method read.
public static InMemoryMapDataSet read(OsmReader reader, final boolean keepNodeTags, final boolean keepWayTags, final boolean keepRelationTags) throws OsmInputException {
final InMemoryMapDataSet dataSet = new InMemoryMapDataSet();
final TLongObjectMap<OsmNode> nodes = dataSet.getNodes();
final TLongObjectMap<OsmWay> ways = dataSet.getWays();
final TLongObjectMap<OsmRelation> relations = dataSet.getRelations();
reader.setHandler(new OsmHandler() {
@Override
public void handle(OsmBounds bounds) throws IOException {
dataSet.setBounds(bounds);
}
@Override
public void handle(OsmNode node) throws IOException {
if (!keepNodeTags) {
node = new Node(node.getId(), node.getLongitude(), node.getLatitude());
}
nodes.put(node.getId(), node);
}
@Override
public void handle(OsmWay way) throws IOException {
if (!keepWayTags) {
TLongArrayList ids = new TLongArrayList();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
ids.add(way.getNodeId(i));
}
way = new Way(way.getId(), ids);
}
ways.put(way.getId(), way);
}
@Override
public void handle(OsmRelation relation) throws IOException {
if (!keepRelationTags) {
List<OsmRelationMember> members = new ArrayList<>();
for (int i = 0; i < relation.getNumberOfMembers(); i++) {
members.add(relation.getMember(i));
}
relation = new Relation(relation.getId(), members);
}
relations.put(relation.getId(), relation);
}
@Override
public void complete() throws IOException {
// nothing to do here
}
});
reader.read();
return dataSet;
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-core by topobyte.
the class TestDataSetGetters method getRelationSuccessful.
@Test
public void getRelationSuccessful() throws EntityNotFoundException {
OsmRelation relation = data.getRelation(1);
assertEquals(relation.getId(), 1);
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-core by topobyte.
the class TestRelationIterator 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);
RelationIterator relationIterator = new RelationIterator(input.getIterator());
List<OsmRelation> relations = Lists.newArrayList(relationIterator.iterator());
input.close();
assertEquals(data.getRelations().size(), relations.size());
for (int i = 0; i < relations.size(); i++) {
OsmRelation a = relations.get(i);
OsmRelation b = data.getRelations().get(i);
assertTrue(EqualityUtil.equals(a, b));
}
}
use of de.topobyte.osm4j.core.model.iface.OsmRelation in project osm4j-core by topobyte.
the class EntityFinderIgnoreMissing method findRelations.
@Override
public List<OsmRelation> findRelations(TLongCollection ids) {
List<OsmRelation> relations = new ArrayList<>();
TLongIterator idIterator = ids.iterator();
while (idIterator.hasNext()) {
try {
relations.add(entityProvider.getRelation(idIterator.next()));
} catch (EntityNotFoundException e) {
// ignore silently
}
}
return relations;
}
Aggregations