/** * Creates a new instance. * <p> * * @param primitiveBlock The primitive block containing the fields to be decoded. */ public PbfFieldDecoder(Osmformat.PrimitiveBlock primitiveBlock) { this.coordGranularity = primitiveBlock.getGranularity(); this.coordLatitudeOffset = primitiveBlock.getLatOffset(); this.coordLongitudeOffset = primitiveBlock.getLonOffset(); this.dateGranularity = primitiveBlock.getDateGranularity(); Osmformat.StringTable stringTable = primitiveBlock.getStringtable(); strings = new String[stringTable.getSCount()]; for (int i = 0; i < strings.length; i++) { strings[i] = stringTable.getS(i).toStringUtf8(); } }
private Fileformat.BlobHeader readHeader(int headerLength) throws IOException { byte[] headerBuffer = new byte[headerLength]; dis.readFully(headerBuffer); Fileformat.BlobHeader blobHeader = Fileformat.BlobHeader.parseFrom(headerBuffer); return blobHeader; }
private byte[] readRawBlob(Fileformat.BlobHeader blobHeader) throws IOException { byte[] rawBlob = new byte[blobHeader.getDatasize()]; dis.readFully(rawBlob); return rawBlob; }
private void processRelations(List<Osmformat.Relation> relations, PbfFieldDecoder fieldDecoder) { for (Osmformat.Relation relation : relations) { Map<String, String> tags = buildTags(relation.getKeysList(), relation.getValsList(), fieldDecoder); ReaderRelation osmRelation = new ReaderRelation(relation.getId()); osmRelation.setTags(tags); buildRelationMembers(osmRelation, relation.getMemidsList(), relation.getRolesSidList(), relation.getTypesList(), fieldDecoder); // Add the bound object to the results. decodedEntities.add(osmRelation); } }
private void processNodes(List<Osmformat.Node> nodes, PbfFieldDecoder fieldDecoder) { for (Osmformat.Node node : nodes) { Map<String, String> tags = buildTags(node.getKeysList(), node.getValsList(), fieldDecoder); ReaderNode osmNode = new ReaderNode(node.getId(), fieldDecoder.decodeLatitude(node .getLat()), fieldDecoder.decodeLatitude(node.getLon())); osmNode.setTags(tags); // Add the bound object to the results. decodedEntities.add(osmNode); } }
private byte[] readBlobContent() throws IOException { Fileformat.Blob blob = Fileformat.Blob.parseFrom(rawBlob); byte[] blobData; if (blob.hasRaw()) { blobData = blob.getRaw().toByteArray(); } else if (blob.hasZlibData()) { Inflater inflater = new Inflater(); inflater.setInput(blob.getZlibData().toByteArray()); blobData = new byte[blob.getRawSize()]; try { inflater.inflate(blobData); } catch (DataFormatException e) { throw new RuntimeException("Unable to decompress PBF blob.", e); } if (!inflater.finished()) { throw new RuntimeException("PBF blob contains incomplete compressed data."); } inflater.end(); } else { throw new RuntimeException("PBF blob uses unsupported compression, only raw or zlib may be used."); } return blobData; }
private void processOsmPrimitives(byte[] data) throws InvalidProtocolBufferException { Osmformat.PrimitiveBlock block = Osmformat.PrimitiveBlock.parseFrom(data); PbfFieldDecoder fieldDecoder = new PbfFieldDecoder(block); for (Osmformat.PrimitiveGroup primitiveGroup : block.getPrimitivegroupList()) { processNodes(primitiveGroup.getDense(), fieldDecoder); processNodes(primitiveGroup.getNodesList(), fieldDecoder); processWays(primitiveGroup.getWaysList(), fieldDecoder); processRelations(primitiveGroup.getRelationsList(), fieldDecoder); } }
private void processWays(List<Osmformat.Way> ways, PbfFieldDecoder fieldDecoder) { for (Osmformat.Way way : ways) { Map<String, String> tags = buildTags(way.getKeysList(), way.getValsList(), fieldDecoder); ReaderWay osmWay = new ReaderWay(way.getId()); osmWay.setTags(tags); // Build up the list of way nodes for the way. The node ids are // delta encoded meaning that each id is stored as a delta against // the previous one. long nodeId = 0; LongIndexedContainer wayNodes = osmWay.getNodes(); for (long nodeIdOffset : way.getRefsList()) { nodeId += nodeIdOffset; wayNodes.add(nodeId); } decodedEntities.add(osmWay); } }
private void processNodes(Osmformat.DenseNodes nodes, PbfFieldDecoder fieldDecoder) { List<Long> idList = nodes.getIdList(); List<Long> latList = nodes.getLatList(); List<Long> lonList = nodes.getLonList(); Iterator<Integer> keysValuesIterator = nodes.getKeysValsList().iterator(); tags = new HashMap<>(Math.max(3, 2 * (nodes.getKeysValsList().size() / 2) / idList.size()));
private void processOsmHeader(byte[] data) throws InvalidProtocolBufferException { Osmformat.HeaderBlock header = Osmformat.HeaderBlock.parseFrom(data); for (String feature : header.getRequiredFeaturesList()) { if (supportedFeatures.contains(feature)) { } else { long milliSecondDate = header.getOsmosisReplicationTimestamp(); fileheader.setTag("timestamp", Helper.createFormatter().format(new Date(milliSecondDate * 1000))); decodedEntities.add(fileheader);
private void getNextBlob() { try { // Read the length of the next header block. This is the only time // we should expect to encounter an EOF exception. In all other // cases it indicates a corrupt or truncated file. int headerLength; try { headerLength = dis.readInt(); } catch (EOFException e) { eof = true; return; } if (log.isLoggable(Level.FINER)) { log.finer("Reading header for blob " + dataBlockCount++); } Fileformat.BlobHeader blobHeader = readHeader(headerLength); if (log.isLoggable(Level.FINER)) { log.finer("Processing blob of type " + blobHeader.getType() + "."); } byte[] blobData = readRawBlob(blobHeader); nextBlob = new PbfRawBlob(blobHeader.getType(), blobData); } catch (IOException e) { throw new RuntimeException("Unable to get next blob from PBF stream.", e); } }
/** * <code>optional .OSMPBF.DenseNodes dense = 2;</code> */ @java.lang.Override public org.openstreetmap.osmosis.osmbinary.Osmformat.DenseNodes getDense() { return instance.getDense(); } /**
/** * <code>optional .OSMPBF.HeaderBBox bbox = 1;</code> */ @java.lang.Override public boolean hasBbox() { return instance.hasBbox(); } /**
/** * <code>repeated string optional_features = 5;</code> */ @java.lang.Override public com.google.protobuf.ByteString getOptionalFeaturesBytes(int index) { return instance.getOptionalFeaturesBytes(index); } /**
/** * <code>required sint64 left = 1;</code> */ public Builder setLeft(long value) { copyOnWrite(); instance.setLeft(value); return this; } /**
/** * <code>repeated .OSMPBF.Node nodes = 1;</code> */ private void clearNodes() { nodes_ = emptyProtobufList(); } /**
/** * <code>optional .OSMPBF.DenseNodes dense = 2;</code> */ private void setDense( org.openstreetmap.osmosis.osmbinary.Osmformat.DenseNodes.Builder builderForValue) { dense_ = builderForValue.build(); bitField0_ |= 0x00000001; } /**
/** * <code>repeated .OSMPBF.Way ways = 3;</code> */ public Builder addWays(org.openstreetmap.osmosis.osmbinary.Osmformat.Way value) { copyOnWrite(); instance.addWays(value); return this; } /**
/** * <pre> * DELTA coded * </pre> * * <code>repeated sint32 uid = 4 [packed = true];</code> */ private void clearUid() { uid_ = emptyIntList(); }
/** * <code>repeated int32 version = 1 [packed = true];</code> */ @java.lang.Override public int getVersionCount() { return instance.getVersionCount(); } /**