How do I extract some data using QGIS?

23 views
Skip to first unread message

Marc Hillman

unread,
May 15, 2024, 6:09:42 PMMay 15
to QGIS Australia User Group
There is a Shapefile that can be downloaded from https://osmdata.openstreetmap.de/download/land-polygons-split-4326.zip that contains geometry for the Earths surface in 1x1 degree blocks, i.e. 32400 of them. The attributes of the data are x (longitude) and y (latitude). I wish to produce a list of all 32400 squares with a simple boolean indicating whether the square contains geometry, or not, i.e. whether that particular square is over land, or not, so I'm looking for 32400 line of x,y,boolean.

I have tried interrogating the Shapefile, square by square, but it's going to take a week to go through all of them. Is there a QGIS script/query that will do this for me? Warning - my level of knowledge of QGIS is minimal, so you'll have to explain it to a 10 year old.

John Bryant

unread,
May 15, 2024, 11:18:05 PMMay 15
to australian-qg...@googlegroups.com
I'll have a go :)

Here's one way to do it:

1) "Dissolve" the shapefile using the x & y attributes. This gives you one multipolygon per 1 degree grid cell, where land exists. (Output A)
2) Create a point grid of the world using the "Create grid" tool, with this grid extent: -180, 180, -90, 90 and a spacing of 1 degree. This gives you the full set of 1 degree grid cells for the entire world, all 64800 of them. (Output B)
3) Prepare A & B by creating a new attribute on each, using the Field Calculator, with an expression something like:
  • "x" ||','|| "y" (on A)
  • "left" ||','|| "top" (on B)
4) Join A & B on the new attributes, using "Join Attributes by Field Value" (input layer is A, input layer 2 is B). Make sure "Discard records which could not be joined" is NOT checked, so you also keep the rows with no land.

This will give you an output with all 64800 cells listed, where the ones that contain land have attributes from the land polygons. It should then be straightforward to modify the attributes to whatever form you like (eg "Refactor Fields").

Cheers, John

image.png
On Thu, 16 May 2024 at 06:09, Marc Hillman <myhi...@gmail.com> wrote:
There is a Shapefile that can be downloaded from https://osmdata.openstreetmap.de/download/land-polygons-split-4326.zip that contains geometry for the Earths surface in 1x1 degree blocks, i.e. 32400 of them. The attributes of the data are x (longitude) and y (latitude). I wish to produce a list of all 32400 squares with a simple boolean indicating whether the square contains geometry, or not, i.e. whether that particular square is over land, or not, so I'm looking for 32400 line of x,y,boolean.

I have tried interrogating the Shapefile, square by square, but it's going to take a week to go through all of them. Is there a QGIS script/query that will do this for me? Warning - my level of knowledge of QGIS is minimal, so you'll have to explain it to a 10 year old.

--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/australian-qgis-user-group/34ce3f8b-7470-46c9-abcf-baac7ac60c9bn%40googlegroups.com.

Juan Fernando Berrío

unread,
May 15, 2024, 11:46:29 PMMay 15
to australian-qg...@googlegroups.com
Hello Marc,

There are so many different ways to achieve this - it's a very nice example of a task that different people could solve successfully in very different ways.

1. John Bryant's way - it should work well, and it's very convenient since it's all done within QGIS. 

2. Python - use a small script that reads all the shapefiles in a folder, and returns a list of the shapefiles which are not empty.  You can manipulate the resulting file names in Python or Excel to create the desired output.  In Python, I would use 'glob' and 'geopandas' in the script - they can do this easily together. 

3. Using a CMD window directly - use the DIR command to list all the *.dbf files in the folder, sorted by size (the empty ones will all come last or first).  This may work well (or not) but it's very simple and quick to do, and easy to check.  You can manipulate the resulting list of files in a text editor or in excel to create your desired output.

4. Ask chatGPT!  Its answers are getting better by the minute - it should be able to explain any of the options mentioned above in detail, or it may provide its own solution (probably better than any of ours). Remember the key to chatGPT is being very specific and clear when you formulate the question.  You can ask it to do it using a particular tool or workflow, etc.

Good luck and happy GISing,
Juan


Marc Hillman

unread,
May 28, 2024, 9:48:07 PMMay 28
to QGIS Australia User Group
SOLVED. I misunderstood the data structure. The very presence of a 1 x 1 cell means that there is land in that cell. I only have to interrogate the metadata to get the answer I need.

Emma Hain

unread,
May 28, 2024, 10:09:05 PMMay 28
to australian-qg...@googlegroups.com
Apologies for this - it was sitting in the folder to be approved to be released. I have now resorted my filters in order for them to be brought to my attention asap

--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.


--
Emma Hain — Product Manager/Senior GIS Analyst
em...@north-road.com
https://north-road.com
North Road
Cartography • Development • Spatial Analysis


north-road.com


Reply all
Reply to author
Forward
0 new messages