-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Geometria più vicina e filtro condizionato | ||
|
||
Tre layer: | ||
1. Layer di punti che rappresenta delle utenze (**layer1**). | ||
2. Layer di punti derivante da un rilevamento topografico (**layer2**). | ||
3. Layer di poligoni rappresentante degli edifici (**layer3**). | ||
|
||
Popolare un nuovo campo del `layer1` con il valore dell'attributo presente nel `layer2` relativo alla geometria più vicina a condizione che i punti ricadono nello steso poligono, `layer3`. | ||
|
||
Esempio: | ||
|
||
soluzione di Andrea Giudiceandrea | ||
``` | ||
attribute( | ||
array_filter( | ||
overlay_nearest( 'layer2', $currentfeature, limit:=-1 ), | ||
attribute( @element, 'IDp' ) = "IDp" )[0], 'IDl2' ) | ||
``` | ||
|
||
Soluzione pigreco | ||
|
||
``` | ||
relation_aggregate( | ||
relation:='rel', | ||
aggregate:='array_agg', | ||
expression:="IDl2") | ||
[ | ||
with_variable('fufu', | ||
array_foreach( | ||
relation_aggregate( | ||
relation:='rel', | ||
aggregate:='array_agg', | ||
expression:=$geometry), | ||
distance($geometry,@element)), | ||
array_find(@fufu,array_min(@fufu))) | ||
] | ||
``` | ||
|
||
Soluzione pigreco in SQL | ||
|
||
```sql | ||
SELECT l1."IDAG" AS la1 , id, shortestline(l1."geom", l2."geom") as geom | ||
FROM "layer1" l1 , "layer2" l2 | ||
WHERE l1."IDAG"=l2."IDAG" | ||
group by l1."IDAG" | ||
having min(st_distance(l1."geom", l2."geom")) | ||
``` | ||
|
||
### prova tu | ||
|
||
[dati e progetto QGIS 3.12](https://mega.nz/file/lUgwhIIA#gEwH2RpsdkNFGWM6qvqDFnXcMS6IIlfqhnkJnH3m164) | ||
|
||
--- | ||
|
||
Funzioni e variabili utilizzate: | ||
|
||
* [with_variable](../gr_funzioni/variabili/with_variable.md) | ||
* [array_find](../gr_funzioni/array/array_unico.md#array_find) | ||
* [array_filter](../gr_funzioni/array/array_unico.md#array_filter) | ||
* [array_agg](../gr_funzioni/aggrega/aggrega_unico.md#array_agg) | ||
* [line_locate_point](../gr_funzioni/geometria/geometria_unico.md#line_locate_point) | ||
* [line_interpolate_point](../gr_funzioni/geometria/geometria_unico.md#line_interpolate_point) | ||
* [intersection](../gr_funzioni/geometria/geometria_unico.md#intersection) | ||
* [length](../gr_funzioni/geometria/geometria_unico.md#length) | ||
* [\$geometry](../gr_funzioni/geometria/geometria_unico.md#geometry) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Geometria più vicina con filtro condizionato | ||
|
||
Due layer di punti: `layer1` con attributo `id1` e `layer2` con `id2`.<br> | ||
A partire dal `layer1`, ottenere per ogni punto del `layer1` tutti i punti del `layer2` dove `id2` ha un valore diverso da `id1` (collegarli con un segmento). | ||
|
||
Esempio: | ||
|
||
![](https://i.stack.imgur.com/NsXXB.png) | ||
|
||
Come si evince dallo screenshot, i punti in rosso devono collegarsi con i punti blu che hanno `id` differente. Il punto 6 è rimasto isolato perché non cisono punti vicini e con id diverso da 6. | ||
|
||
Espressione utilizzata: | ||
|
||
``` | ||
collect_geometries( | ||
make_line( | ||
$geometry, | ||
geometry(get_feature('layer2','id2', | ||
attribute( | ||
array_filter( | ||
overlay_nearest('layer2',$currentfeature,limit:=-1), | ||
attribute( @element, 'id2' ) != "id1" )[0], 'id2' )))) | ||
) | ||
``` | ||
|
||
idea presa da qui: | ||
|
||
- [stackexchange](https://gis.stackexchange.com/questions/391120/qgis-expression-with-overlay-fuction-filter-condition-based-on-comparison-of-at) | ||
|
||
|
||
### prova tu | ||
- [GitHub](https://github.com/qgis/QGIS/issues/43146#issuecomment-836472827) | ||
- [dati](https://drive.switch.ch/index.php/s/af5cHue6P3NA9xM) | ||
|
||
--- | ||
|
||
Funzioni e variabili utilizzate: | ||
|
||
* [array_filter](../gr_funzioni/array/array_unico.md#array_filter) | ||
* [overlay_nearest](../gr_funzioni/geometria/geometria_unico.md#overlay_nearest) | ||
* [attribute](../gr_funzioni/record_e_attributi/record_e_attributi_unico/#attribute) | ||
* [make_line](../gr_funzioni/geometria/geometria_unico.md#make_line) | ||
* [collect_geometries](../gr_funzioni/geometria/geometria_unico.md#collect_geometries) | ||
* [$geometry](../gr_funzioni/geometria/geometria_unico.md#geometry) | ||
* [geometry](../gr_funzioni/geometria/geometria_unico.md#geometry_1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters