Skip to content

Commit

Permalink
- renamed OSM header 'Bbox' to 'BoundingBox'
Browse files Browse the repository at this point in the history
- refactoring
  • Loading branch information
Karsten Klompmaker committed Jun 16, 2017
1 parent 9c2131c commit 51ecde2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
20 changes: 6 additions & 14 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"errors"
"fmt"
"io"
"time"
"sync"
"time"

"github.com/golang/protobuf/proto"
"github.com/qedus/osmpbf/OSMPBF"
Expand Down Expand Up @@ -42,7 +42,7 @@ type Bbox struct {
}

type Header struct {
Bbox *Bbox
BoundingBox *Bbox
RequiredFeatures []string
OptionalFeatures []string
WritingProgram string
Expand Down Expand Up @@ -139,12 +139,7 @@ func (dec *Decoder) SetBufferSize(n int) {
// Get the file header
func (dec *Decoder) Header() (*Header, error) {
// deserialize the file header
err := dec.readOSMHeader()
if err != nil {
return nil, err
}

return dec.header, nil
return dec.header, dec.readOSMHeader()
}

// Start decoding process using n goroutines.
Expand All @@ -153,8 +148,7 @@ func (dec *Decoder) Start(n int) error {
n = 1
}

err := dec.readOSMHeader()
if err != nil {
if err := dec.readOSMHeader(); err != nil {
return err
}

Expand Down Expand Up @@ -184,13 +178,11 @@ func (dec *Decoder) Start(n int) error {
// start reading OSMData
go func() {
var inputIndex int
var blobHeader *OSMPBF.BlobHeader
var blob *OSMPBF.Blob
for {
input := dec.inputs[inputIndex]
inputIndex = (inputIndex + 1) % n

blobHeader, blob, err = dec.readFileBlock()
blobHeader, blob, err := dec.readFileBlock()
if err == nil && blobHeader.GetType() != "OSMData" {
err = fmt.Errorf("unexpected fileblock of type %s", blobHeader.GetType())
}
Expand Down Expand Up @@ -388,7 +380,7 @@ func (dec *Decoder) decodeOSMHeader(blob *OSMPBF.Blob) error {
// read bounding box if it exists
if headerBlock.Bbox != nil {
// Units are always in nanodegree and do not obey granularity rules. See osmformat.proto
header.Bbox = &Bbox{
header.BoundingBox = &Bbox{
Left: 1e-9 * float64(*headerBlock.Bbox.Left),
Right: 1e-9 * float64(*headerBlock.Bbox.Right),
Bottom: 1e-9 * float64(*headerBlock.Bbox.Bottom),
Expand Down
6 changes: 3 additions & 3 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var (
erc uint64 = 12833

eh = &Header{
Bbox: &Bbox{
BoundingBox: &Bbox{
Right: 0.335437,
Left: -0.511482,
Bottom: 51.28554,
Expand Down Expand Up @@ -168,12 +168,12 @@ func downloadTestOSMFile(t *testing.T) {
}

func checkHeader(a *Header) bool {
if a == nil || a.Bbox == nil || a.RequiredFeatures == nil {
if a == nil || a.BoundingBox == nil || a.RequiredFeatures == nil {
return false
}

// check bbox
if a.Bbox.Right != eh.Bbox.Right || a.Bbox.Left != eh.Bbox.Left || a.Bbox.Top != eh.Bbox.Top || a.Bbox.Bottom != eh.Bbox.Bottom {
if a.BoundingBox.Right != eh.BoundingBox.Right || a.BoundingBox.Left != eh.BoundingBox.Left || a.BoundingBox.Top != eh.BoundingBox.Top || a.BoundingBox.Bottom != eh.BoundingBox.Bottom {
return false
}

Expand Down

0 comments on commit 51ecde2

Please sign in to comment.