PostgreSQL/PostGIS data to Matlab - How to display

7 views (last 30 days)
I have successfully connected to a postgreSQL database from matlab and importad a field that contains geometric data (postgreSQL data type of the field is 'geometry'). Here's my code.
curs = exec(conn, 'select location from gps'); setdbprefs('DataReturnFormat','cellarray'); curs = fetch(curs, 10); AA = curs.Data
this gives the following output: [1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
[1x1 org.postgresql.util.PGobject]
The field 'location' contains point features and the postgreSQL data type is geometry. I want to display the actual values. Please tell me a way to do that.
  1 Comment
Ross
Ross on 13 Jan 2017
Obviously really old post, but the easier way it to use SQL to convert the location into x, y and z coordinates in the query.
SELECT ST_X(location_column_name), ST_Y(location_column_name), ST_Z(location_column_name) FROM table_name

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 11 Jun 2011
It appears to me from the documentation that it would go like this:
numA = length(AA);
Geometries = cell(numA,1);
for Gidx = 1:numA;
G = AA(Gidx).getGeometry;
NP = G.numPoints;
Points = cell(NP,1);
for PN = 1:NP
P = G.getPoint(PN);
Points{PN} = [P.x, P.y, P.z];
end
Geometries{Gidx} = Points;
end
I am not sure if there needs to be a step to go from PGobject to PGgeometry.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!