Estou a tentar usar a nova função <->) (Geometry Distance Centroid<http://postgis.refractions.net/docs/geometry_distance_centroid.html>) para em cada registo da minha tabela (cosn1) calcular a distância ao poligono mais próximo com a mesma classe.
Tentei o seguinte código SQL: WITH index_query AS ( SELECT g1.gid As ref_gid, ST_Distance(g1.the_geom,g2.the_geom) As ENN FROM "cosn1" As g1, "cosn1" As g2 WHERE g1.gid <> g2.gid AND g1.class = g2.class ORDER BY g1.gid, g1.the_geom <-> g2.the_geom) SELECT DISTINCT ON (ref_gid) ref_gid, ENN FROM index_query ORDER BY ref_gid, ENN; Mas depois apercebi-me da seguinte nota: Note: Index only kicks in if one of the geometries is a constant (not in a subquery/cte). e.g. 'SRID=3005;POINT(1011102 450541)'::geometry instead of a.geom O que quer dizer que o Indice Espacial não é utilizado, e que a consulta demora praticamente o mesmo tempo que a versão para postgis 1.5: SELECT DISTINCT ON(g1.gid) g1.gid As ref_gid, ST_Distance(g1.the_geom,g2.the_geom) As ENN FROM "cosn1" As g1, "cosn1" As g2 WHERE g1.gid <> g2.gid AND g1.class = g2.class ORDER BY g1.gid, ST_Distance(g1.the_geom,g2.the_geom) Alguém tem alguma sugestão para que possa contornar esta limitação da função? Obrigado, Alexandre Neto
_______________________________________________ Portugal mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/portugal
