Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working version of challenge #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"io/ioutil"
"log"

pb "github.com/dougreese/sdgopher-201609/vectorTile"
"github.com/golang/protobuf/proto"
)

// printValue prints key/value of a tile layer.
func printValue(key string, val *pb.Tile_Value) {
switch {
case nil != val.StringValue:
log.Printf("- %s: %s", key, *val.StringValue)
case nil != val.FloatValue:
log.Printf("- %s: %f", key, *val.FloatValue)
case nil != val.DoubleValue:
log.Printf("- %s: %f", key, *val.DoubleValue)
case nil != val.IntValue:
log.Printf("- %s: %d", key, *val.IntValue)
case nil != val.UintValue:
log.Printf("- %s: %d", key, *val.UintValue)
case nil != val.SintValue:
log.Printf("- %s: %d", key, *val.SintValue)
default:
log.Println("I'm confused!")
}
}

func main() {
fname := "2751.vector.pbf"

log.Printf("Reading protobuf file: %s\n", fname)
in, err := ioutil.ReadFile(fname)
if err != nil {
log.Fatalln("Error reading file:", err)
}
tile := &pb.Tile{}
if err := proto.Unmarshal(in, tile); err != nil {
log.Fatalln("Failed to parse tile:", err)
}

layers := tile.Layers
log.Println("Num layers", len(layers))

for i := 0; i < len(layers); i++ {
layer := layers[i]
log.Println("Name:", layer.GetName())

keys := layer.GetKeys()
values := layer.GetValues()

for j := 0; j < len(keys); j++ {
val := values[j]
printValue(keys[j], val)
}
}

log.Println("Success!")
}
112 changes: 66 additions & 46 deletions vectorTile/vector_tile.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vectorTile/vector_tile.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Protocol Version 1

syntax = "proto2";
package vector_tile;

option optimize_for = LITE_RUNTIME;
Expand Down Expand Up @@ -44,7 +45,7 @@ message Tile {
optional GeomType type = 3 [ default = UNKNOWN ];

// Contains a stream of commands and parameters (vertices).
// A detailed description on geometry encoding is located in
// A detailed description on geometry encoding is located in
// section 4.3 of the specification.
repeated uint32 geometry = 4 [ packed = true ];
}
Expand Down