Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion geos/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package geos_test
import (
"fmt"

"github.com/paulsmith/gogeos/geos"
"github.com/helmi03/gogeos/geos"
)

func ExampleGeometry_LineInterpolatePoint() {
Expand Down
2 changes: 1 addition & 1 deletion geos/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"code.google.com/p/draw2d/draw2d"

"github.com/paulsmith/gogeos/geos"
"github.com/helmi03/gogeos/geos"
)

const (
Expand Down
8 changes: 7 additions & 1 deletion geos/geom.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ func (g *Geometry) String() string {
return str
}

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

// EWKB returns the geometry encoded as a Well-Known Binary (WKB) with SRID meta data.
func (g *Geometry) EWKB() ([]byte, error) {
encoder := newWkbEncoder()
return encoder.encodeEWkb(g)
}

// Hex returns the geometry as a Well-Known Binary (WKB) hex-encoded byte slice.
func (g *Geometry) Hex() ([]byte, error) {
encoder := newWkbEncoder()
Expand Down
2 changes: 1 addition & 1 deletion geos/geos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestVersion(t *testing.T) {
const re = `3\.3\.\d+-CAPI-1\.7\.\d+$`
const re = `3\.[34]?\.\d+-CAPI-1\.[78]?\.\d+( .+)?$`
version := Version()
matched, err := regexp.MatchString(re, version)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions geos/wkb.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ func encodeWkb(e *wkbEncoder, g *Geometry, fn func(*C.GEOSWKBWriter, *C.GEOSGeom
return out, nil
}

func (e *wkbEncoder) encodeEWkb(g *Geometry) ([]byte, error) {
srid, _ := g.SRID()
if srid > 0 {
cGEOSWKBWriter_setIncludeSRID(e.w, C.char(1))
}
return encodeWkb(e, g, cGEOSWKBWriter_write)
}

func (e *wkbEncoder) encode(g *Geometry) ([]byte, error) {
return encodeWkb(e, g, cGEOSWKBWriter_write)
}
Expand Down
24 changes: 24 additions & 0 deletions geos/wkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package geos

import (
"bytes"
"encoding/hex"
"strings"
"testing"
)

Expand Down Expand Up @@ -72,6 +74,16 @@ var wkbEncoderHexTests = []struct {
{"POINT(-117 35)", []byte("01010000000000000000405DC00000000000804140")},
}

var ewkbEncoderHexTests = []struct {
wkt string
srid int
wkb []byte
}{
{"POINT(-117 35)", 4326, []byte("0101000020E61000000000000000405DC00000000000804140")},
{"POINT(-117 35)", 900913, []byte("010100002031BF0D000000000000405DC00000000000804140")},
{"POINT(-117 35)", 0, []byte("01010000000000000000405DC00000000000804140")},
}

func TestWkbEncoderEncodeHex(t *testing.T) {
wktDecoder := newWktDecoder()
wkbEncoder := newWkbEncoder()
Expand All @@ -85,4 +97,16 @@ func TestWkbEncoderEncodeHex(t *testing.T) {
t.Errorf("#%d: want %v got %v", i, string(test.wkb), string(actual))
}
}
for i, test := range ewkbEncoderHexTests {
g1 := Must(wktDecoder.decode(test.wkt))
g1.SetSRID(test.srid)
eg1, err := wkbEncoder.encodeEWkb(g1)
if err != nil {
panic(err)
}
actual := []byte(strings.ToUpper(hex.EncodeToString(eg1)))
if !bytes.Equal(actual, test.wkb) {
t.Errorf("#%d: want %v got %v", i, string(test.wkb), string(actual))
}
}
}