use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.
the class WayWriterTest method testProcessNormalWay.
/**
* Test writing out a normal Way element.
*/
@Test
public final void testProcessNormalWay() {
Way way = new Way(new CommonEntityData(1234, 2, timestamp, new OsmUser(23, "someuser"), 0));
way.getWayNodes().add(new WayNode(1235));
way.getWayNodes().add(new WayNode(1236));
way.getTags().add(new Tag("waykey", "wayvalue"));
testWayWriter.process(way);
try {
testBufferedWriter.flush();
} catch (IOException e) {
e.printStackTrace();
fail("IOException");
}
String[] strArray = testWriter.toString().split("\\n", 5);
assertTrue("Way opening element does not match.", strArray[0].matches(wayOpeningMatch));
assertTrue("Way node 1 does not match.", strArray[1].matches(wayNode1Match));
assertTrue("Way node 2 does not match.", strArray[2].matches(wayNode2Match));
assertTrue("Way tag does not match.", strArray[3].matches(wayTagMatch));
assertTrue("Way closing element does not match.", strArray[4].matches(wayClosingMatch));
}
use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.
the class WayWriterTest method testProcessWayWithNoUser.
/**
* Test writing of a Way element with no user.
*/
@Test
public final void testProcessWayWithNoUser() {
Way way = new Way(new CommonEntityData(1234, 2, timestamp, OsmUser.NONE, 0));
way.getWayNodes().add(new WayNode(1235));
way.getWayNodes().add(new WayNode(1236));
way.getTags().add(new Tag("waykey", "wayvalue"));
testWayWriter.process(way);
try {
testBufferedWriter.flush();
} catch (IOException e) {
e.printStackTrace();
fail("IOException");
}
String wayOpeningNoUserMatch = "^\\s*<way\\s*" + "id=['\"]1234['\"]\\s*" + "version=['\"]2['\"]\\s*" + "timestamp=['\"]2013-10-07T10:24:31Z?['\"]\\s*" + ">\\s*";
String[] strArray = testWriter.toString().split("\\n", 5);
assertTrue("Way opening element does not match.", strArray[0].matches(wayOpeningNoUserMatch));
assertTrue("Way node 1 does not match.", strArray[1].matches(wayNode1Match));
assertTrue("Way node 2 does not match.", strArray[2].matches(wayNode2Match));
assertTrue("Way tag does not match.", strArray[3].matches(wayTagMatch));
assertTrue("Way closing element does not match.", strArray[4].matches(wayClosingMatch));
}
use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.
the class TagFilter method matches.
/**
* Checks whether the Entity in a container has tags that match this filter.
*
* @param container
* The container holding the entity whose tags shall be examined.
*/
private boolean matches(EntityContainer container) {
boolean matched = false;
for (Tag tag : container.getEntity().getTags()) {
String key = tag.getKey();
if (tagKeys.contains(key)) {
matched = true;
break;
}
Set<String> values = tagKeyValues.get(key);
if ((values != null) && values.contains(tag.getValue())) {
matched = true;
break;
}
}
return matched;
}
use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.
the class OsmosisBinaryParser method parseRelations.
@Override
protected void parseRelations(List<Osmformat.Relation> rels) {
for (Osmformat.Relation i : rels) {
List<Tag> tags = new ArrayList<Tag>();
for (int j = 0; j < i.getKeysCount(); j++) {
tags.add(new Tag(getStringById(i.getKeys(j)), getStringById(i.getVals(j))));
}
long id = i.getId();
long lastMid = 0;
List<RelationMember> nodes = new ArrayList<RelationMember>();
for (int j = 0; j < i.getMemidsCount(); j++) {
long mid = lastMid + i.getMemids(j);
lastMid = mid;
String role = getStringById(i.getRolesSid(j));
EntityType etype = null;
if (i.getTypes(j) == Osmformat.Relation.MemberType.NODE) {
etype = EntityType.Node;
} else if (i.getTypes(j) == Osmformat.Relation.MemberType.WAY) {
etype = EntityType.Way;
} else if (i.getTypes(j) == Osmformat.Relation.MemberType.RELATION) {
etype = EntityType.Relation;
} else {
// TODO; Illegal file?
assert false;
}
nodes.add(new RelationMember(mid, etype, role));
}
// long id, int version, TimestampContainer timestampContainer,
// OsmUser user,
// long changesetId, Collection<Tag> tags,
// List<RelationMember> members
Relation tmp;
if (i.hasInfo()) {
Osmformat.Info info = i.getInfo();
tmp = new Relation(new CommonEntityData(id, info.getVersion(), getDate(info), getUser(info), info.getChangeset(), tags), nodes);
} else {
tmp = new Relation(new CommonEntityData(id, NOVERSION, NODATE, OsmUser.NONE, NOCHANGESET, tags), nodes);
}
sink.process(new RelationContainer(tmp));
}
}
use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.
the class PbfBlobDecoder method processNodes.
private void processNodes(Osmformat.DenseNodes nodes, PbfFieldDecoder fieldDecoder) {
List<Long> idList = nodes.getIdList();
List<Long> latList = nodes.getLatList();
List<Long> lonList = nodes.getLonList();
// Ensure parallel lists are of equal size.
if ((idList.size() != latList.size()) || (idList.size() != lonList.size())) {
throw new OsmosisRuntimeException("Number of ids (" + idList.size() + "), latitudes (" + latList.size() + "), and longitudes (" + lonList.size() + ") don't match");
}
Iterator<Integer> keysValuesIterator = nodes.getKeysValsList().iterator();
Osmformat.DenseInfo denseInfo;
if (nodes.hasDenseinfo()) {
denseInfo = nodes.getDenseinfo();
} else {
denseInfo = null;
}
long nodeId = 0;
long latitude = 0;
long longitude = 0;
int userId = 0;
int userSid = 0;
long timestamp = 0;
long changesetId = 0;
for (int i = 0; i < idList.size(); i++) {
CommonEntityData entityData;
org.openstreetmap.osmosis.core.domain.v0_6.Node node;
// Delta decode node fields.
nodeId += idList.get(i);
latitude += latList.get(i);
longitude += lonList.get(i);
if (denseInfo != null) {
// Delta decode dense info fields.
userId += denseInfo.getUid(i);
userSid += denseInfo.getUserSid(i);
timestamp += denseInfo.getTimestamp(i);
changesetId += denseInfo.getChangeset(i);
// Build the user, but only if one exists.
OsmUser user;
if (userId >= 0) {
user = new OsmUser(userId, fieldDecoder.decodeString(userSid));
} else {
user = OsmUser.NONE;
}
entityData = new CommonEntityData(nodeId, denseInfo.getVersion(i), fieldDecoder.decodeTimestamp(timestamp), user, changesetId);
} else {
entityData = new CommonEntityData(nodeId, EMPTY_VERSION, EMPTY_TIMESTAMP, OsmUser.NONE, EMPTY_CHANGESET);
}
// Build the tags. The key and value string indexes are sequential
// in the same PBF array. Each set of tags is delimited by an index
// with a value of 0.
Collection<Tag> tags = entityData.getTags();
while (keysValuesIterator.hasNext()) {
int keyIndex = keysValuesIterator.next();
if (keyIndex == 0) {
break;
}
if (!keysValuesIterator.hasNext()) {
throw new OsmosisRuntimeException("The PBF DenseInfo keys/values list contains a key with no corresponding value.");
}
int valueIndex = keysValuesIterator.next();
Tag tag = new Tag(fieldDecoder.decodeString(keyIndex), fieldDecoder.decodeString(valueIndex));
tags.add(tag);
}
node = new org.openstreetmap.osmosis.core.domain.v0_6.Node(entityData, fieldDecoder.decodeLatitude(latitude), fieldDecoder.decodeLongitude(longitude));
// Add the bound object to the results.
decodedEntities.add(new NodeContainer(node));
}
}
Aggregations