Verifica se il risultato di st_difference è vuoto
Sto cercando di selezionare linee che tocchino completamente un poligono (non solo in un singolo punto).
Presumo che sarebbe un semplice caso di st_isempty ( st_difference (geom_a,geom_b)).
Tuttavia, questo non è il caso, come puoi vedere nella figura seguente.
Vorrei che fossero restituite solo le linee gialle evidenziate. Che cosa sto facendo di sbagliato?
(Potrei risolverlo con un confronto tra stringhe, ma vorrei evitare l'invocazione extra "st_astext").
La domanda:
SELECT a.geometry,
a.id as a_id,
b.FID as b_id,
st_astext(ST_GeometryN(st_difference(a.geometry,b.geometry),1)) as st_difference,
st_isempty(ST_GeometryN(st_difference(a.geometry,b.geometry),1)) as st_isempty
FROM a
INNER JOIN b ON st_touches(a.geometry,b.geometry)
Risposte
Per il tuo problema, posso suggerire di provare un altro approccio utilizzando il ST_IsValid()che è un booleano e funziona come T(1)/F(0). Quindi, la tua query apparirà come
SELECT a.geometry,
a.id as a_id,
b.FID as b_id,
st_astext(ST_GeometryN(st_difference(a.geometry, b.geometry), 1)) as st_difference,
ST_IsValid(ST_GeometryN(st_difference(a.geometry, b.geometry), 1)) as st_isvalid
FROM a
INNER JOIN b ON st_touches(a.geometry, b.geometry)
Posso sbagliarmi, ma il tuo problema ha probabilmente qualcosa a che fare con un avviso descritto inST_IsEmpty()
Modificato: 2.0.0 Nelle versioni precedenti di PostGIS ST_GeomFromText('GEOMETRYCOLLECTION(EMPTY)') era consentito. Questo ora è illegale in PostGIS 2.0.0 per conformarsi meglio agli standard SQL/MM