Geographic Information Systems Asked by Matteo Ruzzante on May 24, 2021
I have a set of polygons in JSON or GeoJSON format and a set of points in a CSV (both containing geographic coordinates). I am able to join these two datasets in QGIS and display them.
I want to generate a dummy variable equal to 1
if a point lies inside a polygon and to 0
if it does not.
The 'Points in polygon'
function in QGIS does not help me with regard to this.
The solution has been provided by @DPSSpatial already, but let me try to demonstrate a Virtual Layer
approach (hence sqlite
, as commented by DPSSpatial ):
Please consider some elephants were observed in and out of the Singapore zoo. I would like to mark elephants "inside a green fence".
Virtual Layer
(1) Layer | Add Layer | Add/Edit Virtual Layer
(2) Import Elephants
and zoo
layers
(3) Give a query like below:
SELECT Elephants.*, st_within(Elephants.geometry, zoo.geometry) AS dummy
FROM Elephants, zoo
WHERE st_within(Elephants.geometry, zoo.geometry)
We will get something like:
Oh, sorry you wanted a complete list of [1, 0] in the dummy column... Then remove WHERE (filter) from the above query, i.e.:
SELECT Elephants.*, st_within(Elephants.geometry, zoo.geometry) AS dummy
FROM Elephants, zoo
You will obtain a full listing in the dummy column.
Answered by Kazuhito on May 24, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP