Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Add Hex() output encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsmith committed Jun 13, 2013
1 parent efad85b commit d8b7835
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions geos/geom.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func (g *Geometry) WKB() ([]byte, error) {
return encoder.encode(g)
}

// Hex returns the geometry as a Well-Known Binary (WKB) hex-encoded byte slice.
func (g *Geometry) Hex() ([]byte, error) {
encoder := newWkbEncoder()
return encoder.encodeHex(g)
}

// Linearref functions

// Return distance of point 'p' projected on this geometry from origin.
Expand Down
13 changes: 13 additions & 0 deletions geos/geom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,16 @@ func TestWKB(t *testing.T) {
}
}
}

func TestHex(t *testing.T) {
for i, test := range wkbEncoderHexTests {
g := Must(FromWKT(test.wkt))
hex, err := g.Hex()
if err != nil {
t.Fatalf("#%d %v", i, err)
}
if !bytes.Equal(hex, test.wkb) {
t.Errorf("#%d want %v got %v", string(test.wkb), string(hex))
}
}
}

0 comments on commit d8b7835

Please sign in to comment.