2012-06-23 18 views
5

Bu alt sorgu çalışanBu alt sorguyu nasıl birleştirebilirim?

SEÇ fark ettik ST_Area (ST_Union (ST_Transform (ST_Intersection ((poly1 gelen poly1.the_geom SEÇ NEREDE poly1.polygon_type = 'P'), poly2.the_geom), 3857)))

bu katılmak çalışan anlamlı derecede daha yavaştır poly1 GELEN area_of_P , poly2 OLARAK

SEC ST_AREA (ST_Union (ST_Transform (ST_Intersection (poly1.the_geom, poly2.the_geom), 3857)))

OLARAK area_of_poly

poly2 DAN

SOL st_intersects üzerinde poly1 artır (poly1.the_geom , poly2.the_geom) poly2.polygon_type = 'P', ancak

, bu ikinci jo genişletmeye gerek

ined versiyonu örneğin

ST_Area (ST_Union (ST_Transform (ST_Intersection ((poly1 gelen poly1.the_geom SEÇ, hesaplanan, belirli bir alan tipi alanı ile, her biri daha fazla sütun geri WHERE poly1.polygon_type =, 'P'), poly2.the_geom), 3857))) area_of_P OLARAK ,

ST_Area (ST_Union (ST_Transform (ST_Intersection ((WHERE poly1.polygon_type = 'S'), poly2.the_geom), 3857 poly1 gelen poly1.the_geom SEÇ))) AS area_of_S

poly1, poly2

cevap

6

Bunu deneyin.

SELECT ST_AREA(ST_Union(ST_Transform(ST_Intersection(poly1.the_geom,poly2.the_geom),3857))) 

AS area_of_poly 

FROM poly2 

LEFT JOIN poly1 on st_intersects(poly1.the_geom,poly2.the_geom) 

WHERE poly2.polygon_type IN ('P', 'S') 

Düzenleme:

SELECT ST_AREA(ST_Union(ST_Transform(ST_Intersection(ps.the_geom,poly2.the_geom),3857))) AS area_of_P, 
     ST_AREA(ST_Union(ST_Transform(ST_Intersection(ss.the_geom,poly2.the_geom),3857))) AS area_of_S 
FROM poly2 
JOIN poly1 ps ON poly2.polygon_type = 'P' AND st_intersects(ps.the_geom,poly2.the_geom) 
JOIN poly1 ss ON poly2.polygon_type = 'S' AND st_intersects(ss.the_geom,poly2.the_geom) 
+0

Üzgünüm, bu açık hale gelmiş olmalıdır. İki sütun döndürmek istiyorum. Biri poligon tipi 'P', diğeri ise poligon tipi 'S' alanıdır. – John

+0

Güncellenen cevaba bakınız. –

+0

Tam olarak ihtiyacım olduğu gibi çalışır. Teşekkürler Brett. – John

İlgili konular