PostgreSQL/PostGIS data to Matlab - How to display

4 次查看(过去 30 天)
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 个评论
Ross
Ross 2017-1-13
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

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2011-6-11
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.

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by