Skip to content

Commit

Permalink
fixed extension fron png to PNG
Browse files Browse the repository at this point in the history
  • Loading branch information
bogind committed May 20, 2024
1 parent 6157660 commit 0766a03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions _posts/2020-11-25-qgis-expression-engine-1-json-hstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
layout: post
title: 'Exploring The QGIS Expression Engine, Part 1: Getting Values From JSON & HSTORE'
tags: [OpenStreetMap,QGIS,JSON,Expressions,HSTORE]
thumbnail-img: /assets/img/blog/qgis_expression_1_json_1.png
cover-img: /assets/img/blog/qgis_expression_1_json_1.png
thumbnail-img: /assets/img/blog/qgis_expression_1_json_1.PNG
cover-img: /assets/img/blog/qgis_expression_1_json_1.PNG
share-title: 'Exploring The QGIS Expression Engine, Part 1: Getting Values From JSON & HSTORE'
share-description: How to take work with HSTORE and JSON fields in the QGIS expression engine
share-img: /assets/img/blog/qgis_expression_1_json_1.png
share-img: /assets/img/blog/qgis_expression_1_json_1.PNG
comments: true
author: Dror Bogin
---

This will be the first post of as many as I get around to write about using the QGIS expression engine for selection, geometry generation and calculations to speed up and automate some analysis.


![]({{ '/assets/img/blog/qgis_expression_1_json_1.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_1_json_1.PNG' | relative_url }})

If you ever downloaded OpenStreetMap data, you found the `tags` or `other_tags` field which is filled with either an [hstore](https://www.postgresql.org/docs/current/hstore.html) field if you used the data from the [GeoFabrik download site](https://download.geofabrik.de/) they are made up of "key"=>"value" pairs seperated by commas, these are additional attributes contained within one field. It's handy if you want to store different attributes for each row in your data. OpenStreetMap does this because not all features of the same type have all the attributes, for examples not all bars need an attribute of "payment:bitcoin".

![]({{ '/assets/img/blog/qgis_expression_1_json_2.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_1_json_2.PNG' | relative_url }})

So how can we get the data out of that field?

Expand All @@ -32,7 +32,7 @@ map_get( hstore_to_map( "other_tags" ),'payment:bitcoin') = 'yes'

These are the businesses in Tel Aviv that accept bitcoin:

![]({{ '/assets/img/blog/qgis_expression_1_json_3.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_1_json_3.PNG' | relative_url }})

Note that there are more points in the image than just points of interest, if you got a national pbf file from GeoFabrik, using hstore_to_map can help you cut it to distinguishable layers.

Expand All @@ -42,16 +42,16 @@ We used the `other_tags` field and create a `map` object from it, what that is,

our map object will look like this:

![]({{ '/assets/img/blog/qgis_expression_1_json_4.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_1_json_4.PNG' | relative_url }})

The idea is, converting the string we get from OSM to an object that QGIS can search in easily instead of using some fancy regex to find the right value we want.

### A JSON example:

![]({{ '/assets/img/blog/qgis_expression_1_json_5.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_1_json_5.PNG' | relative_url }})

Using the same method works great on JSON fields as well, in this case I had a layer with a JSON field containing the Israeli Knesset election results, and what I wanted to get was a single party's share of the votes stored in the field.

![]({{ '/assets/img/blog/qgis_expression_1_json_6.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_1_json_6.PNG' | relative_url }})

This method is used to either split up a layer by a field that exists in only some of the extra tags or to add new fields based on these json/hstore fields.
14 changes: 7 additions & 7 deletions _posts/2020-12-03-qgis-expression-engine-2-dwithin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
layout: post
title: 'Exploring The QGIS Expression Engine, Part 2: What's Missing From Select By Location'
tags: [QGIS,Expressions,Select Within Distance,aggregate]
thumbnail-img: /assets/img/blog/qgis_expression_2_dwithin_1.png
cover-img: /assets/img/blog/qgis_expression_2_dwithin_1.png
thumbnail-img: /assets/img/blog/qgis_expression_2_dwithin_1.PNG
cover-img: /assets/img/blog/qgis_expression_2_dwithin_1.PNG
share-title: 'Exploring The QGIS Expression Engine, Part 2: What's Missing From Select By Location'
share-description: How to select within distance with the QGIS expression engine
share-img: /assets/img/blog/qgis_expression_2_dwithin_1.png
share-img: /assets/img/blog/qgis_expression_2_dwithin_1.PNG
comments: true
author: Dror Bogin
---
Expand All @@ -15,7 +15,7 @@ author: Dror Bogin

For some reason the QGIS **select by location** tool does not allow selecting within a distance, that's something that bothered me over the last few years I've been using QGIS, but creating a buffer and then intersecting wasn't that bad. I mean, even ArcMap has that feature, but no way was I gonna open that mess again.

![]({{ '/assets/img/blog/qgis_expression_2_dwithin_2.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_2_dwithin_2.PNG' | relative_url }})

This is something done in a not very complicated way with the expression engine, with **select by expression**.

Expand All @@ -33,7 +33,7 @@ get_feature('Countries_50m',

Now note that the output of this expression is the feature (or row) itself, and not the geometry.

![]({{ '/assets/img/blog/qgis_expression_2_dwithin_3.png' | relative_url }})
![]({{ '/assets/img/blog/qgis_expression_2_dwithin_3.PNG' | relative_url }})

To get the geometry for that feature, which is the first parameter needed for the `buffer` function, we'll have to wrap the first function with the `geometry` function which accepts a feature.

Expand Down Expand Up @@ -61,7 +61,7 @@ buffer(



![Our buffer in purple, visualized with a geometry generator expression]({{ '/assets/img/blog/qgis_expression_2_dwithin_1.png' | relative_url }})
![Our buffer in purple, visualized with a geometry generator expression]({{ '/assets/img/blog/qgis_expression_2_dwithin_1.PNG' | relative_url }})

We now have the geometry of the buffer we want to use for comparison all we have to do is use an expression for selecting intersecting geometries from our layer.
Derived attributes of a feature (not a layer) are marked with `$` which we can see in the `$geometry` attribute.
Expand Down Expand Up @@ -90,7 +90,7 @@ I'll use the lakes and airports layer from natural earth for this example.

I want to select all the airports within a 1 degree buffer from any lake that borders on more than one country, Like Lake Superior which borders on both the United Stated and Canada.

![The lakes in red are within one country, the airports in black are further away then our rule]({{ '/assets/img/blog/qgis_expression_2_dwithin_4.png' | relative_url }})
![The lakes in red are within one country, the airports in black are further away then our rule]({{ '/assets/img/blog/qgis_expression_2_dwithin_4.PNG' | relative_url }})


But I don't want just Lake Superior, I want all lakes that have that condition. So I'll use the admin field and check for the admin-0 or admin-0 more values.
Expand Down

0 comments on commit 0766a03

Please sign in to comment.