Skip to content
Merged
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
6 changes: 6 additions & 0 deletions bounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ func (b *Bounds) ContainsNode(n *Node) bool {

return true
}

// ObjectID always returns 0 because bounds do not have an id.
// It exists to implement the Object interface.
func (b *Bounds) ObjectID() ObjectID {
return 0
}
1 change: 1 addition & 0 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type Object interface {
private()
}

func (n *Bounds) private() {}
func (n *Node) private() {}
func (w *Way) private() {}
func (r *Relation) private() {}
Expand Down
5 changes: 5 additions & 0 deletions osmxml/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Loop:

s.next = nil
switch strings.ToLower(se.Name.Local) {
case "bounds":
bounds := &osm.Bounds{}
err = s.decoder.DecodeElement(&bounds, &se)
s.next = bounds
case "node":
node := &osm.Node{}
err = s.decoder.DecodeElement(&node, &se)
Expand Down Expand Up @@ -122,6 +126,7 @@ Loop:

// Object returns the most recent token generated by a call to Scan
// as a new osm.Object. This interface is implemented by:
// *osm.Bounds
// *osm.Node
// *osm.Way
// *osm.Relation
Expand Down
24 changes: 24 additions & 0 deletions osmxml/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ func TestScanner_userNote(t *testing.T) {
}
}

func TestScanner_bounds(t *testing.T) {
r := boundsReader()
scanner := New(context.Background(), r)
defer scanner.Close()

if v := scanner.Scan(); !v {
t.Fatalf("should read first scan: %v", scanner.Err())
}

b := scanner.Object().(*osm.Bounds)
if b.MinLat != 1 || b.MinLon != 2 || b.MaxLat != 3 || b.MaxLon != 4 {
t.Fatalf("did not scan correctly, got: %v", b)
}
}

func TestAndorra(t *testing.T) {
f, err := os.Open("../testdata/andorra-latest.osm.bz2")
if err != nil {
Expand Down Expand Up @@ -232,6 +247,15 @@ func userNoteReader() io.Reader {
return bytes.NewReader(data)
}

func boundsReader() io.Reader {
data := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<osm>
<bounds minlat="1" minlon="2" maxlat="3" maxlon="4"/>
</osm>`)

return bytes.NewReader(data)
}

func changesetReader() io.Reader {
data := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="replicate_changesets.rb" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
Expand Down