pigreco / spatial-join-condizionato

Collega ciascuna scuola all'università più vicina nella stessa regione amministrativa - 2023-08-25 Sfida di analisi spaziale https://twitter.com/spatialthinkies/status/1695021747177951435

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spatial Join Condizionato

2023-08-25 Sfida di analisi spaziale

Collega ciascuna scuola all'università più vicina nella stessa regione amministrativa.

Thread: https://treeverse.app/view/xlb1zSBR

Totò FIANDACA

https://twitter.com/totofiandaca/status/1695093176304812192

Strumento:

  1. QGIS desktop
  2. Espressioni di QGIS

PASSO 1:

Trasferire fid del layer admin_boundaries ai due layer puntuali schools e colleges:

aggiungere un attributo IDp numerico e popolarlo con:

overlay_within(
    layer:='admin_boundaries',
    expression:="fid"
)[0]

PASSO 2:

per collegare (tramite un segmento) ciascuna scuola (schools) all'università (colleges) più vicina nelle stessa regione amministrativa, usare l'espressione:

make_line(
    eval('overlay_nearest(\'colleges\',
          $geometry,filter:=IDp='||"IDp"||')')[0],
          $geometry)

nel generatore di geometrie:

DATI e PROGETTO

DATI

ALTRE ESPRESSIONI

make_line(@geometry,
          geometry(
            array_filter( 
            overlay_nearest('colleges',@feature,limit:=-1), 
            attribute( @element, 'IDp' ) = "IDp" )[0]))

RELAZIONE N:N

Creando due relazione di progetto su colleges e schools (perché la relazione tra loro è N:N)

https://github.com/pyarchinit/selectbyrelationship_repo

TABELLA INTERMEDIA

Nella tabella degli attributi delle schools aggiungo un attributo c_osm_id e lo popolo con l'espressione:

eval('overlay_nearest(\'colleges\',
          osm_id,filter:=IDp='||"IDp"||')')[0]

vedi progetto_rel

Reymar SANCHEZ

Strumento:

  1. PostgreSQL/PostGIS
  2. SQL

https://twitter.com/SanchezReymar/status/1695078310198280503/

Dati caricati in PostgreSQL/PostGIS

QUERY

-- AGGIUNGO shapename DI admin_boundaries A colleges

ALTER TABLE colleges ADD COLUMN shapename varchar (100);

UPDATE colleges a SET shapename = b."shapeName"
FROM admin_boundaries b
WHERE ST_Contains (b.geom, a.geom);

-- AGGIUNGO shapename DI admin_boundaries A schools

ALTER TABLE schools ADD COLUMN shapename varchar (100);

UPDATE schools a SET shapename = b."shapeName" 
FROM admin_boundaries b
WHERE ST_Contains (b.geom, a.geom);

-- NEAREST

SELECT osm_id,schools,colleges,ST_Makeline(ageom,bgeom) geom
    FROM (
    SELECT a.osm_id,a.name schools, b.name colleges, 
        row_number() over (partition by a.osm_id ORDER BY ST_Distance (a.geom,b.geom)) r, 
        a.geom ageom, b.geom bgeom
    FROM schools a JOIN colleges b ON ST_DWithin (a.geom,b.geom,1)
    WHERE a."shapename" = b."shapename") t
WHERE r = 1;

Bert Temme

https://twitter.com/berttemme/status/1695090882247082239

Strumento:

  1. duckDB
  2. SQL

repo: https://github.com/bertt/spatial_analysis_challenge/blob/main/README.md

PS: non ho verificato!!!

Postholer - GIS Resources

https://twitter.com/postholer/status/1696047017490030692

Strumento:

  1. bash;
  2. GDAL/OGR
  3. SQL
ogr2ogr -nln paths -dialect sqlite -sql
"SELECT
  r.*
FROM
  (
    SELECT
      b.shapeID AS admin,
      c.osm_id AS college,
      s.osm_id AS school,
      makeline(c.geom, s.geom) AS linegeom,
      st_length (makeline(c.geom, s.geom)) AS linelen
    FROM
      admin boundaries b
      JOIN (
        SELECT
          (ROW_NUMBER() OVER()) AS fid,
          *
        FROM
          colleges
      ) c ON st_intersects(c.geom, b.geom)
      JOIN (
        SELECT
          (ROW_NUMBER() OVER()) AS fid,
          *
        FROM
          schools
      ) s ON st_intersects(s.geom, b.geom)
    GROUP BY
      b.shapeName,
      c.fid,
      s.fid
    ORDER BY
      linelen asc
  ) r
GROUP BY
  r.school"
newdata.gpkg layers.gpkg

MAHESH KUMAR

https://twitter.com/MAHESHK92842090/status/1696112436678734058

Strumento:

  1. QGIS desktop
  2. plugin RefFunction dreprecato
  3. espressioni di QGIS
make_line ($geometry, geometry(get:feature('colleges', 'fid', array_filter(aggregate(layer:='colleges',aggregate:='array_agg',expression:=geomnearest('colleges,'fid'), filter:="admin" = attribute(@parent,'admin'),order_by:0distance($geometry,geometry(@parent)))))))

PS: non ho verificato!!!

RIFERIMENTI

video Youtube

DISCLAIMER

Il presente contenuto è stato realizzato da Salvatore Fiandaca nel mese di agosto 2023 utilizzando QGIS 3.28 Firenze LTR e distribuito con licenza CC BY 4.0

About

Collega ciascuna scuola all'università più vicina nella stessa regione amministrativa - 2023-08-25 Sfida di analisi spaziale https://twitter.com/spatialthinkies/status/1695021747177951435