opendatasicilia / tansignari

"T'ansignari e t'appeddiri"
http://tansignari.opendatasicilia.it
Creative Commons Attribution 4.0 International
18 stars 10 forks source link

[ogr2ogr] sintassi per fare una join tra due shapefile #218

Closed pigreco closed 2 years ago

pigreco commented 2 years ago

Ho due shapefile identici (test1.shp, test2.shp) come struttura dati e numero di righe:

ID, nome, valore

ho usato questa sintassi per fare una JOIN tra i due shapefile (devo unire il campo valore):

ogr2ogr -sql "select test1.*, test2.valore AS cucu FROM test1 JOIN './test2.shp'.test2 ON test1.valore = 'test2.shp'.valore" ./test.shp ./test1.shp

il file test.shp dovrebbe essere il terzo shapefile con la JOIN

errore:

ERROR 1: SQL Expression Parsing Error: syntax error, unexpected '.', expecting end of string. Occurred around :
shp'.test2 ON test1.valore = 'test2.shp'.valore

image

dati: andrea.zip

image

pigreco commented 2 years ago

Ho fatto altri test e qualche passo avanti:

il comando di sotto sembra funzionare parzialmente (non ho più errori), però non capisco perché non aggiunge i valori nel campo unito:

ogr2ogr -sql "select t1.*, t2.valore FROM test1 t1 JOIN './test2.shp'.test2 t2 ON t1.valore=t2.valore" ./testk.shp ./test1.shp

testk.shp è il nuovo shp di output

ecco output

image

pigreco commented 2 years ago

Ho capito, errore mio (assegnavo campo correlato sbagliato), il comando corretto è:

ogr2ogr -sql \ 
"SELECT t1.*, t2.valore \ 
FROM test1 t1 JOIN './test2.shp'.test2 t2 ON t1.id=t2.id" \ 
./testkk.shp ./test1.shp

image

aborruso commented 2 years ago

Grande Totò.

Mi spiace non avere potuto darti supporto, ma ero certo che avresti trovato la soluzione

pigreco commented 2 years ago

ricetta pubblicata

https://tansignari.opendatasicilia.it/ricette/bash/sintassi_join_ogr/