ST_Intersection

Definition

ST_Intersection takes two ST_Geometry objects and returns the intersection set as a two-dimensional ST_Geometry object.

Syntax

sde.st_intersection (g1 sde.st_geometry, g2 sde.st_geometry)

Return type

ST_Geometry

Example

The fire marshal must obtain the areas of the hospitals, schools, and nursing homes intersected by the radius of a possible hazardous waste contamination.

The hospitals, schools, and nursing homes are stored in the sensitive_areas table that is created with the CREATE TABLE statement that follows. The shape column, defined as a polygon, stores the outline of each of the sensitive areas.

The hazardous sites are stored in the hazardous_sites table created with the CREATE TABLE statement that follows. The site column, defined as a point, stores a location that is the geographic center of each hazardous site.

CREATE TABLE sensitive_areas (id integer, 
                               shape sde.st_geometry); 

CREATE TABLE hazardous_sites (id integer, 
                              site sde.st_geometry);


INSERT INTO sensitive_areas VALUES (
1,
sde.st_geometry ('polygon ((20 30, 30 30, 30 40, 20 40, 20 30))', 0)
);

INSERT INTO sensitive_areas VALUES (
2,
sde.st_geometry ('polygon ((30 30, 30 50, 50 50, 50 30, 30 30))', 0)
);

INSERT INTO sensitive_areas VALUES (
3,
sde.st_geometry ('polygon ((40 40, 40 60, 60 60, 60 40, 40 40))', 0)
);

INSERT INTO hazardous_sites VALUES (
4,
sde.st_geometry ('point (60 60)', 0)
);

INSERT INTO hazardous_sites VALUES (
5,
sde.st_geometry ('point (30 30)', 0)
);

The ST_Buffer function generates a buffer surrounding the hazardous waste sites. The ST_Intersection function generates polygons from the intersection of the buffered hazardous waste sites and the sensitive areas.

Oracle

SELECT sa.id, sde.st_astext (sde.st_intersection (sde.st_buffer (hs.site, .1), sa.shape)) Intersection
FROM SENSITIVE_AREAS sa, HAZARDOUS_SITES hs
WHERE hs.id = 5
AND sde.st_astext (sde.st_intersection (sde.st_buffer (hs.site, .1), sa.shape)) 
NOT LIKE '%EMPTY%';

  ID  INTERSECTION

  1   POLYGON  ((29.90000000 30.00000000, 30.00000000 30.00000000, 30.00000000 30.10000000, 29.993
45969 30.09978589, 29.98694738 30.09914449, 29.98049097 30.09807853, 29.97411809
 30.09659258, 29.96785605 30.09469301, 29.96173166 30.09238795, 29.95577113 30.0
8968727, 29.95000000 30.08660254, 29.94444298 30.08314696, 29.93912386 30.079335
33, 29.93406542 30.07518398, 29.92928932 30.07071068, 29.92481602 30.06593458, 2
9.92066467 30.06087614, 29.91685304 30.05555702, 29.91339746 30.05000000, 29.910
31273 30.04422887, 29.90761205 30.03826834, 29.90530699 30.03214395, 29.90340742
 30.02588191, 29.90192147 30.01950903, 29.90085551 30.01305262, 29.90021411 30.0
0654031, 29.90000000 30.00000000)) 

  2   POLYGON  ((30.00000000 30.00000000, 30.10000000 30.00000000, 30.09978589 30.00654031, 30.099
14449 30.01305262, 30.09807853 30.01950903, 30.09659258 30.02588191, 30.09469301
 30.03214395, 30.09238795 30.03826834, 30.08968727 30.04422887, 30.08660254 30.0
5000000, 30.08314696 30.05555702, 30.07933533 30.06087614, 30.07518398 30.065934
58, 30.07071068 30.07071068, 30.06593458 30.07518398, 30.06087614 30.07933533, 3
0.05555702 30.08314696, 30.05000000 30.08660254, 30.04422887 30.08968727, 30.038
26834 30.09238795, 30.03214395 30.09469301, 30.02588191 30.09659258, 30.01950903
 30.09807853, 30.01305262 30.09914449, 30.00654031 30.09978589, 30.00000000 30.1
0000000, 30 30))

PostgreSQL

SELECT sa.id, sde.st_astext (sde.st_intersection (sde.st_buffer (hs.site, .1), sa.shape)) AS Intersection
FROM sensitive_areas sa, hazardous_sites hs
WHERE hs.id = 5
AND sde.st_astext (sde.st_intersection (sde.st_buffer (hs.site, .1), sa.shape))::varchar  NOT LIKE '%EMPTY%';

  id  intersection

  1  | POLYGON  ((29.90000000 30.00000000, 30 30, 30.00000000 30.1000000, 29.993
45969 30.09978589, 29.98694738 30.09914449, 29.98049097 30.09807853, 29.97411809
 30.09659258, 29.96785605 30.09469301, 29.96173166 30.09238795, 29.95577113 30.0
8968727, 29.95000000 30.08660254, 29.94444298 30.08314696, 29.93912386 30.079335
33, 29.93406542 30.07518398, 29.92928932 30.07071068, 29.92481602 30.06593458, 2
9.92066467 30.06087614, 29.91685304 30.05555702, 29.91339746 30.05000000, 29.910
31273 30.04422887, 29.90761205 30.03826834, 29.90530699 30.03214395, 29.90340742
 30.02588191, 29.90192147 30.01950903, 29.90085551 30.01305262, 29.90021411 30.0
0654031, 29.90000000 30.00000000))

  2  | POLYGON  ((30 30, 30.10000000 30.0000000, 30.09978589 30.00654031, 30.099
14449 30.01305262, 30.09807853 30.01950903, 30.09659258 30.02588191, 30.09469301
 30.03214395, 30.09238795 30.03826834, 30.08968727 30.04422887, 30.08660254 30.0
5000000, 30.08314696 30.05555702, 30.07933533 30.06087614, 30.07518398 30.065934
58, 30.07071068 30.07071068, 30.06593458 30.07518398, 30.06087614 30.07933533, 3
0.05555702 30.08314696, 30.05000000 30.08660254, 30.04422887 30.08968727, 30.038
26834 30.09238795, 30.03214395 30.09469301, 30.02588191 30.09659258, 30.01950903
 30.09807853, 30.01305262 30.09914449, 30.00654031 30.09978589, 30.00000000 30.1
0000000, 30 30))
6/19/2015