フィルターのクリア

PostgreSQL/PostGIS data to Matlab - How to display

4 ビュー (過去 30 日間)
Devinya Herath
Devinya Herath 2011 年 6 月 11 日
コメント済み: Ross 2017 年 1 月 13 日
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 Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by