Skip to content

Conversation

larsbeck
Copy link

@larsbeck larsbeck commented Nov 13, 2023

Description

This PR adds a PBF Encoder. It is inspired by OsmSharp's encoder. Most likely this code can be simplified and made more go idiomatic.

The Encoder has a method Encode(obj osm.Object) error which can be used to encode structs of type osm.Object.

Resolves #48

@larsbeck larsbeck changed the title Add OSM encoder Add OSM PBF encoder May 6, 2024
@larsbeck larsbeck marked this pull request as ready for review May 6, 2024 09:11
Copy link

@Farm-Art Farm-Art left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{""}
	}

@dschep dschep mentioned this pull request Aug 29, 2025
@dschep dschep mentioned this pull request Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEATURE REQUEST: Write to osm.pbf

2 participants