@@ -3,6 +3,7 @@ package ewkb
33import (
44 "bytes"
55 "encoding/binary"
6+ "encoding/hex"
67 "errors"
78 "io"
89
@@ -71,6 +72,7 @@ func MustMarshal(geom orb.Geometry, srid int, byteOrder ...binary.ByteOrder) []b
7172}
7273
7374// Marshal encodes the geometry with the given byte order.
75+ // An SRID of 0 will not be included in the encoding and the result will be a wkb encoding of the geometry.
7476func Marshal (geom orb.Geometry , srid int , byteOrder ... binary.ByteOrder ) ([]byte , error ) {
7577 buf := bytes .NewBuffer (make ([]byte , 0 , wkbcommon .GeomLength (geom , srid != 0 )))
7678
@@ -93,6 +95,27 @@ func Marshal(geom orb.Geometry, srid int, byteOrder ...binary.ByteOrder) ([]byte
9395 return buf .Bytes (), nil
9496}
9597
98+ // MarshalToHex will encode the geometry into a hex string representation of the binary ewkb.
99+ func MarshalToHex (geom orb.Geometry , srid int , byteOrder ... binary.ByteOrder ) (string , error ) {
100+ data , err := Marshal (geom , srid , byteOrder ... )
101+ if err != nil {
102+ return "" , err
103+ }
104+
105+ return hex .EncodeToString (data ), nil
106+ }
107+
108+ // MustMarshalToHex will encode the geometry and panic on error.
109+ // Currently there is no reason to error during geometry marshalling.
110+ func MustMarshalToHex (geom orb.Geometry , srid int , byteOrder ... binary.ByteOrder ) string {
111+ d , err := MarshalToHex (geom , srid , byteOrder ... )
112+ if err != nil {
113+ panic (err )
114+ }
115+
116+ return d
117+ }
118+
96119// NewEncoder creates a new Encoder for the given writer.
97120func NewEncoder (w io.Writer ) * Encoder {
98121 e := wkbcommon .NewEncoder (w )
0 commit comments