Wednesday, 21 February 2018

Can I view a Postgis Geometry Array in QGIS?


I've got an array of geometry as a column in a postgis database. Is it possible to view the data (even the n'th element?) in qgis?




Answer



No, not directly.


However, you can create a VIEW using some fancy SQL, which will open in QGIS. If this is a one-off, you can SELECT INTO a new table instead by modifying the query.


Say you have a table geo_arrays with a geoms geometry array column type. Try this:


CREATE VIEW geo_parts AS
SELECT
row_number() OVER () AS gid,
v.gid as old_gid,
row_number() OVER (PARTITION BY gid) part,
geom

FROM
(SELECT gid, unnest(geoms) AS geom FROM geo_arrays) AS v

Which will give a new gid unique key required by most programs, as well as the old primary key and array part number (if these are useful). If the geometry arrays are heterogeneous (e.g., a mixture of POINT and LINESTRINGs), then in QGIS there will be a layer for each type.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...