0

https://postgis.net/docs/ST_VoronoiPolygons.html

I am trying to load this query result using PostGIS 2.5 connection in QGIS 3.4, QGIS 2.18.

SELECT ST_VoronoiPolygons(geom) As geom FROM (SELECT 'MULTIPOINT (50 30, 60 30, 100 100,10 150, 110 120)'::geometry As geom ) As g;

Getting the error of the vector layer GeometryCollection result as Raster Layer in QGIS.

Results =>

enter image description here

I have tried PostGIS function to verify results

  1. https://postgis.net/docs/ST_IsValid.html
  2. https://postgis.net/docs/ST_MakeValid.html
  3. https://postgis.net/docs/ST_IsValidReason.html

And Applying ST_AsGeoJSON and ST_AsText, results are GeometryCollection, valid, I have imported that GeoJSON in https://mapshaper.org/. the result is correct. on other PostGIS function like ST_CollectionExtract with polygon and ST_Dump working fine with this query result. I have faced this type of error much time before with GeometryCollection result of PostGIS DB Queries in QGIS, so why is QGIS Load GEometryCollection vector query result as raster layer?

0

Qgis does not like GeometryCollection, you should convert geometry collection result of ST_VoronoiPolygons to MultiPolygon using ST_CollectionExtract. For example if you have a point layer to generate voronoi cells:

with p as (
    select ST_Union(geom) as geom from you_point_layer
)
select 1 as id, 
ST_CollectionExtract(ST_VoronoiPolygons(geom), 3) as geom from p;

The second parameter of ST_CollectionExtract is the geometry type to extract (3 = polygon). The result is one multipolygon geometry. Next picture shows how to use it in DB Manager for a point layer to get voronoi cells (varos is my point layer)

Query in DB Manager

And loading it into QGIS:

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.