PostGIS geometry PgDAC
Posted: Fri 13 Mar 2020 11:47
Hi.
I have PostgreSQL database with Postgis geometry.
How to decode postgis binary geometry to 'WKT' or any other format or get PgDAC object (ex. TPgPoint) in Delphi application (or any other)
I also have tried to use postgis function ST_AsText(geometry) in SQL
But this throws me error that function st_astext(public.geometry) doesn't exist.
When I create table using point or polygon data type I can get TPgPoint.
Unfortunately, this isn't Postgis geometry and I can't show this data in application like QGis.
Also I can't show in my application data with Postgis geometry
How to decode Postgis geometry?
I have PostgreSQL database with Postgis geometry.
How to decode postgis binary geometry to 'WKT' or any other format or get PgDAC object (ex. TPgPoint) in Delphi application (or any other)
Code: Select all
procedure TfmMain.Button5Click(Sender: TObject);
var
fld: TField;
pgfld: TPgGeometricField;
pGeom: TPgGeometric;
pPoint: TPgPoint;
pCBlob: TCompressedBlob;
x,y: Double;
begin
PgQuery1.SQL.Clear;
PgQuery1.SQL.Add('SELECT * FROM test_geom');
PgQuery1.Open;
fld := PgQuery1.FieldByName('geometry');
pgfld := TPgGeometricField(fld);
pGeom := pgfld.AsPgGeometric;
pCBlob := TCompressedBlob(pGeom);//works, but how to decode geometry data?
pPoint := TPgPoint(pGeom);//don't work
x := pPoint.X;
y := pPoint.Y;
Code: Select all
PgQuery1.SQL.Add('SELECT ST_AsText(geometry) FROM test_geom');
PgQuery1.Open;
When I create table using point or polygon data type I can get TPgPoint.
Code: Select all
CREATE TABLE test_geom_point
(
geometry point,
id integer NOT NULL
);
INSERT INTO test_geom_point(
geometry, id )
VALUES (point(2,1), 1);
Also I can't show in my application data with Postgis geometry
How to decode Postgis geometry?