Search in sources :

Example 1 with EntityType

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);
        }
    }
}
Also used : EntityType(de.topobyte.osm4j.core.model.iface.EntityType) Compression(de.topobyte.osm4j.pbf.Compression) PrimitiveBlock(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock) EntityGroups(de.topobyte.osm4j.pbf.util.copy.EntityGroups) BlockData(de.topobyte.osm4j.pbf.util.BlockData) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat)

Example 2 with EntityType

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()));
        }
    }
}
Also used : EntityType(de.topobyte.osm4j.core.model.iface.EntityType) FileStructure(de.topobyte.osm4j.pbf.raf.FileStructure) PbfFile(de.topobyte.osm4j.pbf.raf.PbfFile) PbfFile(de.topobyte.osm4j.pbf.raf.PbfFile) File(java.io.File) Interval(de.topobyte.osm4j.pbf.raf.Interval)

Example 3 with EntityType

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();
}
Also used : PrimitiveGroup(de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup) EntityType(de.topobyte.osm4j.core.model.iface.EntityType) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 4 with EntityType

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);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag) ArrayList(java.util.ArrayList) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) EntityType(de.topobyte.osm4j.core.model.iface.EntityType) Relation(de.topobyte.osm4j.core.model.impl.Relation) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) RelationMember(de.topobyte.osm4j.core.model.impl.RelationMember) Tag(de.topobyte.osm4j.core.model.impl.Tag) OsmTag(de.topobyte.osm4j.core.model.iface.OsmTag)

Example 5 with EntityType

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;
}
Also used : EntityType(de.topobyte.osm4j.core.model.iface.EntityType) Osmformat(de.topobyte.osm4j.pbf.protobuf.Osmformat) HashSet(java.util.HashSet)

Aggregations

EntityType (de.topobyte.osm4j.core.model.iface.EntityType)5 Osmformat (de.topobyte.osm4j.pbf.protobuf.Osmformat)3 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)2 OsmTag (de.topobyte.osm4j.core.model.iface.OsmTag)2 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)1 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)1 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)1 Relation (de.topobyte.osm4j.core.model.impl.Relation)1 RelationMember (de.topobyte.osm4j.core.model.impl.RelationMember)1 Tag (de.topobyte.osm4j.core.model.impl.Tag)1 Compression (de.topobyte.osm4j.pbf.Compression)1 PrimitiveBlock (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveBlock)1 PrimitiveGroup (de.topobyte.osm4j.pbf.protobuf.Osmformat.PrimitiveGroup)1 FileStructure (de.topobyte.osm4j.pbf.raf.FileStructure)1 Interval (de.topobyte.osm4j.pbf.raf.Interval)1 PbfFile (de.topobyte.osm4j.pbf.raf.PbfFile)1 BlockData (de.topobyte.osm4j.pbf.util.BlockData)1 EntityGroups (de.topobyte.osm4j.pbf.util.copy.EntityGroups)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1