use of de.topobyte.osm4j.core.model.iface.EntityType in project osm4j-pbf by topobyte.
the class EntitySplit method data.
private void data(Fileformat.Blob blob) throws IOException {
BlockData blockData = PbfUtil.getBlockData(blob);
Osmformat.PrimitiveBlock primBlock = Osmformat.PrimitiveBlock.parseFrom(blockData.getBlobData());
if (!PbfMeta.hasMixedContent(primBlock)) {
// If the block does not contain multiple entity types, we can copy
// the blob without have to recreate the message.
EntityType type = PbfMeta.getContentTypes(primBlock).iterator().next();
if (type == EntityType.Node && copyNodes) {
blockWriterNodes.write(Constants.BLOCK_TYPE_DATA, null, blob);
} else if (type == EntityType.Way && copyWays) {
blockWriterWays.write(Constants.BLOCK_TYPE_DATA, null, blob);
} else if (type == EntityType.Relation && copyRelations) {
blockWriterRelations.write(Constants.BLOCK_TYPE_DATA, null, blob);
}
} else {
// Multiple entity types in the block. Extract types and write to
// appropriate output.
EntityGroups groups = EntityGroups.splitEntities(primBlock);
Compression compression = blockData.getCompression();
if (copyNodes && groups.getNodeGroups().size() > 0) {
copy(blockWriterNodes, groups.getNodeGroups(), primBlock, compression);
}
if (copyWays && groups.getWayGroups().size() > 0) {
copy(blockWriterWays, groups.getWayGroups(), primBlock, compression);
}
if (copyRelations && groups.getRelationGroups().size() > 0) {
copy(blockWriterRelations, groups.getRelationGroups(), primBlock, compression);
}
}
}
use of de.topobyte.osm4j.core.model.iface.EntityType in project osm4j-pbf by topobyte.
the class FindEntityBlockIntervals method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("usage: " + FindEntityBlockIntervals.class.getSimpleName() + " <filename>");
System.exit(1);
}
File file = new File(args[0]);
PbfFile pbfFile = new PbfFile(file);
pbfFile.buildBlockIndex();
FileStructure fileStructure = FileStructureAnalyzer.analyze(pbfFile);
for (EntityType type : EntityType.values()) {
if (!fileStructure.hasType(type)) {
System.out.println(type + ": none");
} else {
Interval blocks = fileStructure.getBlocks(type);
System.out.println(String.format(type + ": [%d, %d]", blocks.getStart(), blocks.getEnd()));
}
}
}
use of de.topobyte.osm4j.core.model.iface.EntityType 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();
}
use of de.topobyte.osm4j.core.model.iface.EntityType in project osm4j-pbf by topobyte.
the class PrimParser method convert.
public OsmRelation convert(Osmformat.Relation r) {
long id = r.getId();
long lastMid = 0;
List<OsmTag> tags = new ArrayList<>();
for (int j = 0; j < r.getKeysCount(); j++) {
tags.add(new Tag(strings[r.getKeys(j)], strings[r.getVals(j)]));
}
List<RelationMember> members = new ArrayList<>();
for (int j = 0; j < r.getMemidsCount(); j++) {
long mid = lastMid + r.getMemids(j);
lastMid = mid;
String role = strings[r.getRolesSid(j)];
Osmformat.Relation.MemberType type = r.getTypes(j);
EntityType t = getType(type);
RelationMember member = new RelationMember(mid, t, role);
members.add(member);
}
OsmMetadata metadata = null;
if (fetchMetadata && r.hasInfo()) {
Osmformat.Info info = r.getInfo();
metadata = convertMetadata(info);
}
return new Relation(id, members, tags, metadata);
}
use of de.topobyte.osm4j.core.model.iface.EntityType in project osm4j-pbf by topobyte.
the class PbfMeta method getContentTypes.
public static Set<EntityType> getContentTypes(Osmformat.PrimitiveBlock block) {
int count = block.getPrimitivegroupCount();
Set<EntityType> types = new HashSet<>();
for (int i = 0; i < count; i++) {
Osmformat.PrimitiveGroup group = block.getPrimitivegroup(i);
EntityType type = getEntityType(group);
if (type != null) {
types.add(type);
}
}
return types;
}
Aggregations