I\'ve been trying to find a way to insert and retrieve geometric types using Golang, and specifically the library gorm. I\'m also attempting to use the library orb that defines
The solution I ended up using was as follows:
First I created new types that wrapped all of the orb types, for example:
type Polygon4326 orb.Polygon
type Point4326 orb.Point
Then I implemented the Scan()
, Value()
methods on each type. I had to however edit the bytes and convert to/from hexadecimal. When you directly query on a spatial column in PostGIS, it will return a hexadecimal representation of EWKB, essentially WKB, but including 4 bytes to represent the projection ID (in my case 4326).
Before inserting, I had to add the bytes that represent the projection of 4326.
Before reading, I had to strip those bytes, since orb's built in scanning expected WKB format.