cridenour / go-postgis

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

function st_geomfromewkt(unknown) does not exist #6

Closed maym86 closed 5 years ago

maym86 commented 6 years ago

When I try the following code I get an error:


pos := postgis.PointZ{lon, lat, height}
cmd = `INSERT INTO ` + estimatesTable + ` (id, ts, pos, type, lat_s, lon_s, height_s, track_id) VALUES ($1, to_timestamp($2::double precision / 1000), ST_GeomFromEWKT($3), $4, $5, $6, $7, $8);`

res, err = signEstimateService.postgresSession.Exec(cmd, deviceID, ts, pos, signType, latSigma, lonSigma, heightSigma, trackingID)

pq: function st_geomfromewkt(unknown) does not exist

This works when I do it directly using sql as follows:

INSERT INTO test_landmarks.estimates (id, ts, pos, type, lat_s, lon_s, height_s, track_id)
                    VALUES ('TEST', to_timestamp((1517986955612)::double precision / 1000), 
                    ST_GeomFromText('POINTZ(-109.366424 -27.121192 12.1)'), 2, 0.03, 0.03, 0.03, 0);

Am I doing something wrong or is the function somehow not supported by pq?

cridenour commented 6 years ago

Try removing the ST_ as we work with binary data here instead of strings. The function ST_GeomFromEWKT exists, just only with a string parameter, instead of the unknown which in this case is the raw data.

cridenour commented 6 years ago
pos := postgis.PointZ{lon, lat, height}
cmd = `INSERT INTO ` + estimatesTable + ` (id, ts, pos, type, lat_s, lon_s, height_s, track_id) VALUES ($1, to_timestamp($2::double precision / 1000), GeomFromEWKT($3), $4, $5, $6, $7, $8);`

res, err = signEstimateService.postgresSession.Exec(cmd, deviceID, ts, pos, signType, latSigma, lonSigma, heightSigma, trackingID)