I have a set of polygons in json or geojson format and a set of points in 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.
Solution has been provided by DPSSpatial already, but let me try to demonstrate a
Virtual Layer approach (hence
sqlite, as commented by DPSSpatial ):
Example ---------- Please consider some elephants were observed in and out of the Singapore zoo. I would like to mark elephants "inside green fence".
Layer | Add Layer | Add/Edit Virtual Layer
(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 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 full listing in dummy column.