cridenour / go-postgis

PostGIS support for Go. Works with any Postgres driver.
MIT License
107 stars 26 forks source link

Can't INSERT PointS #1

Closed AlekSi closed 8 years ago

AlekSi commented 10 years ago

Hello,

I'm using github.com/lib/pq and trying to insert PointS into database with code like this:

DB.Exec("INSERT INTO pois (lonlat) VALUES ($1)", postgis.PointS{SRID: 4326, X: 42, Y: 77})

It fails with pq: invalid byte sequence for encoding "UTF8": 0x00.

cridenour commented 10 years ago

Hey thanks for taking a look. I'll check it out this evening.

AlekSi commented 10 years ago

Any news?

cridenour commented 10 years ago

So sorry for the long silence.

I just realized tonight the solution is much simpler than I had in my head :frowning:

You'll just need to use GeomFromEWKB() as I do in the README.

DB.Exec("INSERT INTO pois (lonlat) VALUES (GeomFromEWKB($1))", postgis.PointS{SRID: 4326, X: 42, Y: 77})

However when using SELECT, the data will be scanned automatically. I'll see if we can automate this function call.

AlekSi commented 10 years ago

Why are you using WKB instead of WKT in Value()?

cridenour commented 10 years ago

A mix of two reasons. EWKB is how Postgres actually stores the data so there's no chance of loss of accuracy. Secondly, it makes the code easier to maintain.

As you mention, the disadvantage is needing to do GeomFromEWKB but I'm sure there are ways to mitigate that.

AlekSi commented 8 years ago

We ended up implementing our own types, and just few days ago started to open-source them there: https://github.com/mc2soft/pq-types/tree/postgis

cridenour commented 8 years ago

Perfect timing! You got your first star :)