Description
The ST_Within
function returns whether or not one geometry object is
entirely within another geometry object.
Syntax
ST_Within(WritableGeometry geometry1, WritableGeometry geometry2)
Parameters
Parameter | Type | Description |
---|---|---|
geometry1 | WritableGeometry | The first instance of a WritableGeometry. |
geometry2 | WritableGeometry | The second instance of a WritableGeometry. |
Return Values
Return Type | Description |
---|---|
Boolean |
True , if the geometry2 entirely contains
geometry1 ; otherwise, False .If either
|
Examples
SELECT ST_Within(ST_GeomFromWKT(t1.geometry, 'epsg:4326'), ST_GeomFromWKT(t2.geometry, 'epsg:4326'))
AS Result FROM table1 t1, table2 t2;
SELECT L.zipcode as zipcode, SUM(L.insurance) as TotalInsuredAmount, AVG(R.riskdesc) AS RiskScore
FROM book_of_business L, FIRE_RISK_BOUNDRIES R
WHERE ST_Within(ST_GeomFromWKT(L.location), ST_GeomFromWKT(R.geom)) GROUP BY L.zipcode;