2012-06-23 10 views
5

मैंने देखा है कि इस सबक्वेरी चलमैं इस सबक्वायरी को शामिल होने के रूप में कैसे अनुकूलित कर सकता हूं?

चयन ST_Area (ST_Union (ST_Transform (ST_Intersection ((poly1 से poly1.the_geom का चयन करें जहां poly1.polygon_type = 'पी'), poly2.the_geom), 3857)))

area_of_P poly1 से, poly2 के रूप में

इस में शामिल होने के चलाने की तुलना में काफी धीमी है

चयन ST_AREA (ST_Union (ST_Transform (ST_Intersection (poly1.the_geom, poly2.the_geom), 3857)))

के रूप में area_of_poly

poly2 से

बायाँ शामिल हों st_intersects पर poly1 (poly1.the_geom , poly2.the_geom)

कहां poly2.polygon_type = 'पी'

हालांकि, मैं इस दूसरे jo उनका विस्तार करने की जरूरत है ined संस्करण अधिक स्तंभ, प्रत्येक गणना की किसी दिए गए बहुभुज प्रकार के क्षेत्र के साथ वापस जाने के लिए, यानी

चयन ST_Area (ST_Union (ST_Transform (ST_Intersection ((poly1 से poly1.the_geom का चयन करें जहां poly1.polygon_type = 'पी'), poly2.the_geom), 3857))) area_of_P के रूप में,

ST_Area (ST_Union (ST_Transform (ST_Intersection ((poly1 से कहां poly1.polygon_type = 'एस'), poly2.the_geom), 3857 poly1.the_geom का चयन करें)) AS area_of_S

पॉली 1 से, पॉली 2

उत्तर

6

इसे आजमाएं।

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') 

संपादित करें:

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

क्षमा करें, मैं इस स्पष्ट करना चाहिए था। मैं दो कॉलम वापस करना चाहता हूं। एक बहुभुज प्रकार 'पी' का क्षेत्र है, दूसरा बहुभुज प्रकार 'एस' का क्षेत्र है। – John

+0

अद्यतन उत्तर देखें। –

+0

ठीक उसी तरह काम करता है जैसा मुझे इसकी आवश्यकता है। धन्यवाद ब्रेट। – John

संबंधित मुद्दे