Skip to content

Commit

Permalink
feat(optional_way_nodes): put output of way nodes behind cli flag, di…
Browse files Browse the repository at this point in the history
…sable by default

BREAKING CHANGE: waynodes were previously output by default, they are now off by default
  • Loading branch information
missinglink committed Nov 1, 2018
1 parent 0788d03 commit 046fecc
Show file tree
Hide file tree
Showing 13 changed files with 66,508 additions and 2,288,006 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ If you need to target only specific values for a tag you can specify exactly whi

### Denormalization

When processing the ways, the node refs are looked up for you and the lat/lon values are added to each way:
When processing the ways, the node refs are looked up for you and the lat/lon values are added to each way.

Since version `3.0` centroids are also computed for each way.
Since version `3.0` centroids are also computed for each way, since version `5.0` bounds are now also computed.

Output of the `nodes` array (as seen below) is optional, this was disabled by default in version `5.0` but can be enabled with the flag `--waynodes=true`.

```bash
{
Expand Down
Binary file modified build/pbf2json.darwin-x64
Binary file not shown.
Binary file modified build/pbf2json.linux-arm
Binary file not shown.
Binary file modified build/pbf2json.linux-x64
Binary file not shown.
Binary file modified build/pbf2json.win32-x64
Binary file not shown.
14 changes: 11 additions & 3 deletions pbf2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ type settings struct {
LevedbPath string
Tags map[string][]string
BatchSize int
WayNodes bool
}

var emptyLatLons = make([]map[string]string, 0)

func getSettings() settings {

// command line flags
leveldbPath := flag.String("leveldb", "/tmp", "path to leveldb directory")
tagList := flag.String("tags", "", "comma-separated list of valid tags, group AND conditions with a +")
batchSize := flag.Int("batch", 50000, "batch leveldb writes in batches of this size")
wayNodes := flag.Bool("waynodes", false, "should the lat/lons of nodes belonging to ways be printed")

flag.Parse()
args := flag.Args()
Expand All @@ -54,7 +58,7 @@ func getSettings() settings {
// fmt.Print(conditions, len(conditions))
// os.Exit(1)

return settings{args[0], *leveldbPath, conditions, *batchSize}
return settings{args[0], *leveldbPath, conditions, *batchSize, *wayNodes}
}

func main() {
Expand Down Expand Up @@ -154,7 +158,11 @@ func run(d *osmpbf.Decoder, db *leveldb.DB, config settings) {
// compute centroid
var centroid = computeCentroid(latlons)

onWay(v, latlons, centroid)
if config.WayNodes {
onWay(v, latlons, centroid)
} else {
onWay(v, emptyLatLons, centroid)
}
}

case *osmpbf.Relation:
Expand Down Expand Up @@ -195,7 +203,7 @@ type jsonWay struct {
Tags map[string]string `json:"tags"`
// NodeIDs []int64 `json:"refs"`
Centroid map[string]string `json:"centroid"`
Nodes []map[string]string `json:"nodes"`
Nodes []map[string]string `json:"nodes,omitempty"`
}

func onWay(way *osmpbf.Way, latlons []map[string]string, centroid map[string]string) {
Expand Down
Loading

0 comments on commit 046fecc

Please sign in to comment.