1

I am trying to group points using a Virtual layer and create a rectangle covering an extents but I cannot get it to return the geometry.

Current code is this:

SELECT
    VP.Page,
    st_envelope(st_collect(VP.geometry)) AS geometry
FROM
    "Viewpoint Locations" AS VP
GROUP BY
    VP.Page

Coordinates are in OSGB

Sample point:

wkt_geom    ele name    VP  Easting Northing    Date    Time_Only   Distance    Bearing Page
PointZ (347471.40698287688428536 169679.50496837147511542 20.05986800000000159) 20.059868   632 01  347471.407  169679.505  15/11/2021  12:55:23    630.613 165.476 1

Link to file: https://drive.google.com/open?id=101V1qc9KstZ-e9jh-AlUzlT5EAfTkVFf&authuser=gwrichardson%40gmail.com&usp=drive_fs

3
  • Interesting I've tried that and the line "Envelope(AddPoint(MakeLine(p.geometry),StartPoint(MakeLine(p.geometry))))" doesn't appear to be recognised a function (ending up as the column header, with null values). I did try adding "AS geometry" to the end of this line but it still ends up with a column of null values Commented Nov 19, 2021 at 11:45
  • the query is fine, make sure the CRS is properly set/recognized
    – JGH
    Commented Nov 19, 2021 at 13:16
  • I added the CRS and geometry type in the dialogue - no difference. Or do I need to set it in the query? Commented Nov 19, 2021 at 13:29

1 Answer 1

3

After inspecting your input data 'Viewpoint Locations.geojson' I could assume that the visualization issue caused by How QGIS treats your GeoJSON (probably because "QGIS does not support GeometryCollection as a valid geometry type.").

geojson_text_editor

Consult GeoJSON driver help page for detailed explanations on options

When I checked the details of your input file it may look absolutely fine.

input

However, when one try this innocent query over input data, one can get a better understanding that something goes wrong.

SELECT
    VP.Page,
    st_astext(VP.geometry) AS geomtxt
FROM
     "Viewpoint Locations" AS VP 

and the Virtual layer will look as following

vl

As you can see Virtual layer treats each point as GEOMETRYCOLLECTION() instead of initial Point (PointZ). Unfortunately, the ST_Force2D() does not work in Virtual layer.


As a workaround you may follow this workflow:

Step 1. Use the "Drop M/Z values" geoalgorithm

step_1

Step 2. Apply the same query

SELECT
    VP.Page,
    st_envelope(st_collect(VP.geometry)) AS geometry
FROM
    "Viewpoint Locations" AS VP
GROUP BY
    VP.Page

and get the following output

result1


IMHO GeoJSON is not yet in the ideal "relationship" with QGIS. See for instance this thread: Merging layers with different geometry (PointZ and MultiLineStringZ) in QGIS.

However, I could use your query to make envelops with my own Point (PointZ) layer stored in the shapefile, see image below.

result2


References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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