A quick aside regarding the code that you posted. Postgres (bizarrely, IMHO) stores longitude first, then latitude, so:
return fmt.Sprintf("POINT(%v %v)", p.Lat, p.Lng) should be: return fmt.Sprintf("POINT(%v %v)", p.Lng, p.Lat) Thanks for sharing your code! On Tuesday, February 18, 2014 at 5:29:36 PM UTC-5, Peter Nguyen wrote: > > Thanks for all your replies! I managed to create a type that maps to the > geography column of Postgis, thanks to this package > https://github.com/twpayne/gogeom. Here is the code in case anyone was > looking for it: > > http://play.golang.org/p/uKXaGvZ2C2 > > One strange thing is that according to the specification of WKB, the byte > for geometry type should be from 1 to 7. But in the code, I had to use > uint64 which read to a very large number (18580565393409). It's maybe > because of different versions of Postgresq + Postgis, I'm not sure... > > Den tisdagen den 18:e februari 2014 kl. 17:58:32 UTC+1 skrev Andy Balholm: >> >> On Tuesday, February 18, 2014 3:10:32 AM UTC-8, Peter Nguyen wrote: >>> >>> I'm using lib/pg in my project and has now encountered the Postgis >>> geography(POINT,4326) column type that I need to both scan into a Point >>> struct and also inserting Point structs back to that column. The way to >>> insert data into that column type is to call the Postgis function >>> ST_GeometryFromText('POINT(-118.4079 33.9434)', 4326). How can this be >>> solved using the database/sql package? Is there a way using the provided >>> interfaces to map a Point struct into that SQL statement? >>> >> >> If your column type is geography (rather than geometry), it's actually >> simpler than that. You can just do something like this: >> >> create table test (p geography); >> insert into test(p) values ('POINT(-118.4079 33.9434)'); >> >> The ST_GeometryFromText function is unnecessary in this situation. >> Virtually every type in Postgres has an input function that accepts a value >> formatted as text. >> >> On the other hand, when you're scanning a point out of the DB, you do >> need to use the ST_AsText function in your query, since the default output >> format is a bunch of hexadecimal gibberish. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.