Conversation
Add osm pbf encoder
Farm-Art
left a comment
There was a problem hiding this comment.
Hello, thank you for providing this fork. I've used it successfully in one of my internal projects, though not without some (easily fixed) issues. I've pointed them out in this review, didn't have time to submit a proper pull request, though I'm considering making my own fork eventually to alleviate a few other pet peeves I have with this library in general.
|
|
||
| blockData, err := proto.Marshal(block) | ||
| if err != nil { | ||
| return nil |
There was a problem hiding this comment.
Looks like a typo, should return err instead of nil. This came up in my attempt to use this fork, concealing the issue above that quietly omitted all Nodes from the output file.
| } | ||
| } | ||
| groupDense.Denseinfo.Uid = append(groupDense.Denseinfo.Uid, int32(current.UserID-previous.UserID)) | ||
| groupDense.Denseinfo.Version = append(groupDense.Denseinfo.Version, int32(current.Version-previous.Version)) |
There was a problem hiding this comment.
Versions aren't delta-encoded in the spec, this causes issues with the current decoder. Should just append current.Version.
| for k := range e.reverseStringTable { | ||
| delete(e.reverseStringTable, k) | ||
| } | ||
|
|
There was a problem hiding this comment.
I ran into a few issues with Nodes that had empty stringtables, adding this snippet right here before proto.Marshal seemingly solved it for me. I'm assuming it has something to do with missing idx-0 delimiters, but I didn't have time to properly study the spec and figure out if that's the case.
if block.Stringtable == nil {
block.Stringtable = &osmpbf.ForkStringTable{}
}
if block.Stringtable.S == nil {
block.Stringtable.S = []string{""}
}
Description
This PR adds a PBF Encoder. It is inspired by
OsmSharp's encoder. Most likely this code can be simplified and made moregoidiomatic.The
Encoderhas a methodEncode(obj osm.Object) errorwhich can be used to encode structs of typeosm.Object.Resolves #48