3

I have currently added a CSV file of earthquakes on a 7 day basis and added in the URL so that it gets updated automatically. I also have population count data for the whole of Central and South America. What would be the best way to add in buffers (e.g. 5km, 10km, 25km), so they automatically update once an earthquake appears and how would I go about extract the population data within each buffer, so I know the population affected by each.

Moreover, I have events for the world but I only want them for Central and South America. Is there any where I can filter by attributes, so I only have events for these two areas?

enter image description here

6
3

Assuming both, earthquakes and population are vector points, you can create a virtual layer with an expression like this:

SELECT 
e.id, st_buffer(e.geometry,10) as geom2, COUNT(i.geometry) as ncities, SUM(i.population) as affected_population
FROM 
earthquakes as e
JOIN 
Inhabitants as i
ON 
ST_Intersects(st_buffer(e.geometry,10), i.geometry)
GROUP BY 
e.id;

It will create buffers of earthquakes in specified distance (here 10) and count the total affected population + the number of cities. You can include st_transform() if you need all this in a special CRS. The virtual layer will update automatically each time a new point has been added. In worst case you have to zoom in and out or pan the map a little to refresh the canvas.

Make sure to not get lost in the three different geometries:

enter image description here

Here an example:

enter image description here

7
  • Hi there. Thank you for your help. However, every time I put this command into the query, QGIS freezes. Is there any resolution around this. Cheers.
    – LiamHems
    Sep 11 '20 at 17:12
  • @LiamHems sorry, stupid question, but you did adjust all layer and fieldnames to your ones? Thats actually the only reason I can think of it freezing QGIS.
    – MrXsquared
    Sep 11 '20 at 17:38
  • That is okay, I am only a student and quite a basic at QGIS and python! I originally a population raster but used the raster to vector (polygonize) tool to create a vector layer called Inhabitants. Then, I used the expression above and changed the (i.population) field to (i.inhabitants), as that is the fieldname that contains the population data. My other file that I have is called Earthquakes. The population is for the whole of Nicaragua, so could it just freeze/be slow because of this? Hope this helps? Thanks for the help, Liam
    – LiamHems
    Sep 11 '20 at 20:02
  • If your files are really big, that could slow down the progress, of course. Cant tell remotely how much effect this has. How long did you wait when its freezing? Sounds correct, but maybe try the "Test" button before creating the virtual layer to check if it throws back an error.
    – MrXsquared
    Sep 11 '20 at 20:12
  • Also be aware: if you are intersecting population data stored in polygons, the result of the above query will not be correct! Thats because it counts the population of the entire intersected polygon, not just the intersected part. When working with polygons, it is better to use relative numbers such as inhabitants per km² or similar and then calculate the acutal inhabitants by the intersected area. @LiamHems
    – MrXsquared
    Sep 11 '20 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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