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);
switch (method) { case NEW_MUTABLE_INSTANCE: { return new org.openstreetmap.osmosis.osmbinary.Osmformat.HeaderBlock(); if (hasBbox()) { if (!getBbox().isInitialized()) { return null; optionalFeatures_= visitor.visitList(optionalFeatures_, other.optionalFeatures_); writingprogram_ = visitor.visitString( hasWritingprogram(), writingprogram_, other.hasWritingprogram(), other.writingprogram_); source_ = visitor.visitString( hasSource(), source_, other.hasSource(), other.source_); osmosisReplicationTimestamp_ = visitor.visitLong( hasOsmosisReplicationTimestamp(), osmosisReplicationTimestamp_, other.hasOsmosisReplicationTimestamp(), other.osmosisReplicationTimestamp_); osmosisReplicationSequenceNumber_ = visitor.visitLong( hasOsmosisReplicationSequenceNumber(), osmosisReplicationSequenceNumber_, other.hasOsmosisReplicationSequenceNumber(), other.osmosisReplicationSequenceNumber_); osmosisReplicationBaseUrl_ = visitor.visitString( hasOsmosisReplicationBaseUrl(), osmosisReplicationBaseUrl_, other.hasOsmosisReplicationBaseUrl(), other.osmosisReplicationBaseUrl_); if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor .INSTANCE) { if (!parseUnknownField(tag, input)) { done = true;
private void processOsmHeader( byte[] data ) throws InvalidProtocolBufferException Osmformat.HeaderBlock header = Osmformat.HeaderBlock.parseFrom(data); for (String feature : header.getRequiredFeaturesList()) long milliSecondDate = header.getOsmosisReplicationTimestamp(); fileheader.setTag("timestamp", Helper.createFormatter().format(new Date(milliSecondDate * 1000))); decodedEntities.add(fileheader);
if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, getBbox()); size += 1 * getRequiredFeaturesList().size(); size += 1 * getOptionalFeaturesList().size(); .computeStringSize(16, getWritingprogram()); .computeStringSize(17, getSource()); .computeStringSize(34, getOsmosisReplicationBaseUrl());
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 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);
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeMessage(1, getBbox()); } for (int i = 0; i < requiredFeatures_.size(); i++) { output.writeString(4, requiredFeatures_.get(i)); } for (int i = 0; i < optionalFeatures_.size(); i++) { output.writeString(5, optionalFeatures_.get(i)); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeString(16, getWritingprogram()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeString(17, getSource()); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeInt64(32, osmosisReplicationTimestamp_); } if (((bitField0_ & 0x00000010) == 0x00000010)) { output.writeInt64(33, osmosisReplicationSequenceNumber_); } if (((bitField0_ & 0x00000020) == 0x00000020)) { output.writeString(34, getOsmosisReplicationBaseUrl()); } unknownFields.writeTo(output); }
@Override public void parse(Osmformat.HeaderBlock block) { for (String s : block.getRequiredFeaturesList()) { if (s.equals("OsmSchema-V0.6")) { continue; // We can parse this. } if (s.equals("DenseNodes")) { continue; // We can parse this. } throw new OsmosisRuntimeException("File requires unknown feature: " + s); } if (block.hasBbox()) { String source = OsmosisConstants.VERSION; if (block.hasSource()) { source = block.getSource(); } double multiplier = .000000001; double rightf = block.getBbox().getRight() * multiplier; double leftf = block.getBbox().getLeft() * multiplier; double topf = block.getBbox().getTop() * multiplier; double bottomf = block.getBbox().getBottom() * multiplier; Bound bounds = new Bound(rightf, leftf, topf, bottomf, source); sink.process(new BoundContainer(bounds)); } }
@Override public Map<String, Object> apply(Osmformat.HeaderBlock header) { // Check if there are any unsupported features in the file. // Build the list of active and unsupported features in the file. List<String> unsupportedFeatures = new ArrayList<>(); for (String feature : header.getRequiredFeaturesList()) { if (!SUPPORTED_FEATURES.contains(feature)) { unsupportedFeatures.add(feature); } } // We can't continue if there are any unsupported features. We wait // until now so that we can display all unsupported features instead of // just the first one we encounter. if (unsupportedFeatures.size() > 0) { throw new OsmosisRuntimeException("PBF file contains unsupported features " + unsupportedFeatures); } Map<String, Object> osmosisMetadata = new HashMap<>(); if (header.getOptionalFeaturesList().contains("LocationsOnWays")) { osmosisMetadata.put(WayNode.METADATA_KEY_LOCATION_INCLUDED, true); } else { osmosisMetadata.put(WayNode.METADATA_KEY_LOCATION_INCLUDED, false); } return osmosisMetadata; } }
@Override public void parse(Osmformat.HeaderBlock block) { for (String s : block.getRequiredFeaturesList()) { if (s.equals("OsmSchema-V0.6")) { continue; // We can parse this. } if (s.equals("DenseNodes")) { continue; // We can parse this. } throw new IllegalStateException("File requires unknown feature: " + s); } if (block.hasOsmosisReplicationTimestamp()) { long timestamp = block.getOsmosisReplicationTimestamp(); LOG.info("PBF file has a replication timestamp of {}", Instant.ofEpochSecond(timestamp)); entitySink.setReplicationTimestamp(timestamp); } else { LOG.info("PBF file has no replication timestamp."); } }
@Override public void handleBlock(FileBlock message) { // TODO Auto-generated method stub try { if (message.getType().equals("OSMHeader")) { Osmformat.HeaderBlock headerblock = Osmformat.HeaderBlock .parseFrom(message.getData()); parse(headerblock); } else if (message.getType().equals("OSMData")) { Osmformat.PrimitiveBlock primblock = Osmformat.PrimitiveBlock .parseFrom(message.getData()); parse(primblock); } } catch (InvalidProtocolBufferException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new Error("ParseError"); // TODO } }
@Override public void writeBegin() throws IOException { LOG.info("Writing PBF format..."); // Write out a header block Osmformat.HeaderBlock.Builder builder = Osmformat.HeaderBlock.newBuilder(); builder.addRequiredFeatures("DenseNodes").setWritingprogram("Vanilla Extract").build(); if (timestamp > 0) { builder.setOsmosisReplicationTimestamp(timestamp); } writeOneBlob(builder.build()); // Start another thread that will handle compression and writing in parallel. writerThread = new Thread(this); writerThread.start(); }
/** * <pre> * Additional tags to aid in parsing this dataset * </pre> * * <code>repeated string required_features = 4;</code> */ @java.lang.Override public java.util.List<java.lang.String> getRequiredFeaturesList() { return java.util.Collections.unmodifiableList( instance.getRequiredFeaturesList()); } /**
private void processBounds(Bound entity) { Osmformat.HeaderBlock.Builder headerblock = Osmformat.HeaderBlock .newBuilder(); Osmformat.HeaderBBox.Builder bbox = Osmformat.HeaderBBox.newBuilder(); bbox.setLeft(mapRawDegrees(entity.getLeft())); bbox.setBottom(mapRawDegrees(entity.getBottom())); bbox.setRight(mapRawDegrees(entity.getRight())); bbox.setTop(mapRawDegrees(entity.getTop())); headerblock.setBbox(bbox); if (entity.getOrigin() != null) { headerblock.setSource(entity.getOrigin()); } finishHeader(headerblock); }
@Override public BoundContainer apply(Osmformat.HeaderBlock header) { Bound bound; if (header.hasBbox()) { Osmformat.HeaderBBox bbox = header.getBbox(); bound = new Bound(bbox.getRight() * COORDINATE_SCALING_FACTOR, bbox.getLeft() * COORDINATE_SCALING_FACTOR, bbox.getTop() * COORDINATE_SCALING_FACTOR, bbox.getBottom() * COORDINATE_SCALING_FACTOR, header.getSource()); } else { bound = new Bound(header.getSource()); } return new BoundContainer(bound); } }
/** * <pre> * replication timestamp, expressed in seconds since the epoch, * otherwise the same value as in the "timestamp=..." field * in the state.txt file used by Osmosis * </pre> * * <code>optional int64 osmosis_replication_timestamp = 32;</code> */ @java.lang.Override public long getOsmosisReplicationTimestamp() { return instance.getOsmosisReplicationTimestamp(); } /**
/** Write empty header block when there's no bounds entity. */ public void writeEmptyHeaderIfNeeded() { if (headerWritten) { return; } Osmformat.HeaderBlock.Builder headerblock = Osmformat.HeaderBlock.newBuilder(); finishHeader(headerblock); }
/** * <pre> * From the bbox field. * </pre> * * <code>optional string source = 17;</code> */ @java.lang.Override public java.lang.String getSource() { return instance.getSource(); } /**
/** * <code>optional .OSMPBF.HeaderBBox bbox = 1;</code> */ @java.lang.Override public boolean hasBbox() { return instance.hasBbox(); } /**