How custom field types can be used which calls db extension functions? In this case PostGIS .
From PostGIS install page slightly altered:
CREATE TABLE
mytable (
id SERIAL PRIMARY KEY,
geom GEOMETRY(POINT, 26910)
)
;
INSERT INTO
mytable (geom)
VALUES
(ST_GeomFromText('POINT(0 0)', 26910))
;
SELECT
id
FROM
mytable
WHERE
ST_DWithin(geom, ST_GeomFromText('POINT(0 0)', 26910), 1000)
;
How this table is generated in code? And how it is queried?
class mytable
{
[AutoIncrement]
[PrimaryKey]
public int id;
[???]
public ??? geom;
}
Related SO question: How to define 'geography' type using Npgsql and OrmLite (using postgresql, postgis, c#)
Rather an old question but it came up for me when I was looking at this so I thought I would add this in case it helps others. Note that there may well be a better way to do this in ServiceStack now as it has massively increased functionality since the original question
I haven't yet been able to get this working using ServiceStack (the geometry fields return as null) but I have using Npgsql as follows.
SELECT - use ::Text as follows -
var conn = new NpgsqlConnection(connectionString);
conn.Open();
var cmd = new NpgsqlCommand(
"select id, geom :: TEXT from mytable", conn);
INSERT - use a standard insert as follows -
var conn = new NpgsqlConnection(connectionString);
conn.Open();
using (var cmd = new NpgsqlCommand(
"INSERT INTO mytable( geom) VALUES ( st_geomfromtext ( 'POINT(0,0)':: TEXT, 1000))",
conn)){cmd.ExecuteNonQuery()}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.