3.4.6. Relacionamentos Espaciais
3.4.6.1. ST_Relate
Considere os objetos geométricos apresentados na Figura 3.9.
Caso 1:
SELECT ST_Relate(
ST_GeomFromText( 'POLYGON( (1 1, 1 3, 5 3, 5 1, 1 1) )' ),
ST_GeomFromText( 'POLYGON( (3 2, 3 4, 5 4, 5 2, 3 2) )' )
);
Caso 2:
SELECT ST_Relate(
ST_GeomFromText( 'POLYGON( (1 5, 1 7, 3 7, 3 5, 1 5) )' ),
ST_GeomFromText( 'POLYGON( (3 6, 3 7, 7 7, 7 6, 3 6) )' )
);
Caso 3:
SELECT ST_Relate(
ST_GeomFromText( 'POLYGON( (7 1, 7 3, 9 3, 9 1, 7 1) )' ),
ST_GeomFromText( 'POINT( 8 3 )' )
);
Caso 4:
SELECT ST_Relate(
ST_GeomFromText( 'POLYGON( (9 5, 9 7, 11 7, 11 5, 9 5) )' ),
ST_GeomFromText( 'LINESTRING( 10 8, 10 6, 13 6 )' )
);
Caso 5:
SELECT ST_Relate(
ST_GeomFromText( 'LINESTRING( 11 2, 13 4, 15 2 )' ),
ST_GeomFromText( 'LINESTRING( 12 3, 12 1, 15 1 )' )
);
Caso 6:
SELECT ST_Relate(
ST_GeomFromText( 'POLYGON( (1 1, 1 3, 3 3, 3 1, 1 1) )' ),
ST_GeomFromText( 'POINT( 2 2 )' ),
'T*T***F**'
);
Caso 7:
SELECT ST_Relate(
ST_GeomFromText( 'LINESTRING( 5 5, 5 3, 3 3, 3 1, 1 1 )' ),
ST_GeomFromText( 'LINESTRING( 6 4, 6 3, 7 3, 7 1 )' ),
'T*T***F**'
);
3.4.6.2. ST_Equals
O relacionamento espacial ST_Equals
permite saber se duas geometrias A
e B
são toplogicamente iguais.
SELECT ST_Equals(
ST_GeomFromText( 'POLYGON( ( 1 1, 1 5, 5 5, 5 1, 1 1 ) )' ),
ST_GeomFromText( 'POLYGON( (5 3, 5 5, 3 5, 1 5, 1 3, 1 1, 3 1, 5 1, 5 3 ) )' )
);
3.4.6.3. ST_Touches
O relacionamento espacial ST_Touches
diz se duas geometrias se tocam.
Caso 1:
SELECT ST_Touches(
ST_GeomFromText( 'LINESTRING( 1 7, 1 9, 3 9 )' ),
ST_GeomFromText( 'LINESTRING( 1 9, 3 7 )' )
);
Caso 2:
SELECT ST_Touches(
ST_GeomFromText( 'LINESTRING( 1 4, 2 6 )' ),
ST_GeomFromText( 'LINESTRING( 2 6, 3 4 )' )
);
Caso 3:
SELECT ST_Touches(
ST_GeomFromText( 'LINESTRING( 5 6, 5 8, 7 8 )' ),
ST_GeomFromText( 'LINESTRING( 6 6, 6 9 )' )
);
Caso 4:
SELECT ST_Touches(
ST_GeomFromText( 'POLYGON( ( 9 6, 9 8, 12 8, 12 6, 9 6 ) )' ),
ST_GeomFromText( 'POLYGON( ( 12 7, 15 9, 15 5, 12 7 ) )' )
);
Caso 5:
SELECT ST_Touches(
ST_GeomFromText( 'POLYGON( ( 1 1, 1 3, 4 3, 4 1, 1 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 4 2, 4 4, 6 4, 6 2, 4 2 ) )' )
);
Caso 6:
SELECT ST_Touches(
ST_GeomFromText( 'POLYGON( ( 7 1, 7 3, 10 3, 10 1, 7 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 9 2, 13 4, 13 1, 9 2 ) )' )
);
3.4.6.4. ST_Crosses
O relacionamento espacial ST_Crosses
diz se duas geometrias se cruzam.
Caso 1:
SELECT ST_Crosses(
ST_GeomFromText( 'LINESTRING( 0 4, 3 9 )' ),
ST_GeomFromText( 'LINESTRING( 1.5 6.5, 4 4 )' )
);
Caso 2:
SELECT ST_Crosses(
ST_GeomFromText( 'LINESTRING( 4 8, 7 8 )' ),
ST_GeomFromText( 'LINESTRING( 5 6, 5 9 )' )
);
Caso 3:
SELECT ST_Crosses(
ST_GeomFromText( 'LINESTRING( 8 8, 12 8 )' ),
ST_GeomFromText( 'LINESTRING( 9 6, 9 8, 11 8, 11 9 )' )
);
Caso 4:
SELECT ST_Crosses(
ST_GeomFromText( 'LineString( 11 5, 13 5, 13 6 )' ),
ST_GeomFromText( 'POLYGON( ( 12 4, 12 7, 15 7, 15 5, 12 4) )' )
);
Caso 5:
SELECT ST_Crosses(
ST_GeomFromText( 'MultiPoint( 9 2, 9 3, 10 2 )' ),
ST_GeomFromText( 'LineString( 8 1, 8 3, 10 3 )' )
);
Caso 6:
SELECT ST_Crosses(
ST_GeomFromText( 'MultiPoint( 3.5 1, 3.5 2.5, 4.5 1.5, 4.5 2.5 )' ),
ST_GeomFromText( 'POLYGON( ( 1 1, 1 3, 4 3, 4 1, 1 1) )' )
);
3.4.6.5. ST_Within
O relacionamento espacial ST_Within
diz se a geometria A
encontra-se dentro da geometria B
.
Caso 1:
SELECT ST_Within(
ST_GeomFromText( 'POINT( 3 8 )' ),
ST_GeomFromText( 'POLYGON( ( 1 6, 1 9, 5 9, 5 6, 1 6 ) )' )
);
Caso 2:
SELECT ST_Within(
ST_GeomFromText( 'POINT( 6 8 )' ),
ST_GeomFromText( 'POLYGON( ( 6 6, 6 9, 10 9, 10 6, 6 6 ) )' )
);
Caso 3:
SELECT ST_Within(
ST_GeomFromText( 'POLYGON( ( 2 2, 2 4, 4 4, 4 2, 2 2 ) )' ),
ST_GeomFromText( 'POLYGON( ( 1 1, 1 5, 5 5, 5 1, 1 1 ) )' )
);
Caso 4:
SELECT ST_Within(
ST_GeomFromText( 'POLYGON( ( 7 3, 7 5, 9 5, 9 3, 7 3 ) )' ),
ST_GeomFromText( 'POLYGON( ( 6 1, 6 5, 10 5, 10 1, 6 1 ) )' )
);
Caso 5:
SELECT ST_Within(
ST_GeomFromText( 'LINESTRING( 12 7, 12 9, 14 9 )' ),
ST_GeomFromText( 'POLYGON( ( 11 6, 11 9, 15 9, 15 6, 11 6 ) )' )
);
Caso 6:
SELECT ST_Within(
ST_GeomFromText( 'LINESTRING( 11 3, 11 5, 13 5 )' ),
ST_GeomFromText( 'POLYGON( ( 11 1, 11 5, 15 5, 15 1, 11 1 ) )' )
);
3.4.6.6. ST_Contains
O relacionamento espacial ST_Contains
diz se a geometria A
contém a geometria B
.
Caso 1:
SELECT ST_Contains(
ST_GeomFromText( 'POLYGON( ( 1 6, 1 9, 5 9, 5 6, 1 6 ) )' ),
ST_GeomFromText( 'POINT( 3 8 )' )
);
Caso 2:
SELECT ST_Contains(
ST_GeomFromText( 'POLYGON( ( 6 6, 6 9, 10 9, 10 6, 6 6 ) )' ),
ST_GeomFromText( 'POINT( 6 8 )' )
);
Caso 3:
SELECT ST_Contains(
ST_GeomFromText( 'POLYGON( ( 1 1, 1 5, 5 5, 5 1, 1 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 2 2, 2 4, 4 4, 4 2, 2 2 ) )' )
);
Caso 4:
SELECT ST_Contains(
ST_GeomFromText( 'POLYGON( ( 6 1, 6 5, 10 5, 10 1, 6 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 7 3, 7 5, 9 5, 9 3, 7 3 ) )' )
);
Caso 5:
SELECT ST_Contains(
ST_GeomFromText( 'POLYGON( ( 11 6, 11 9, 15 9, 15 6, 11 6 ) )' ),
ST_GeomFromText( 'LINESTRING( 12 7, 12 9, 14 9 )' )
);
Caso 6:
SELECT ST_Contains(
ST_GeomFromText( 'POLYGON( ( 11 1, 11 5, 15 5, 15 1, 11 1 ) )' ),
ST_GeomFromText( 'LINESTRING( 11 3, 11 5, 13 5 )' )
);
3.4.6.7. ST_Overlaps
O relacionamento espacial ST_Overlaps
diz se duas geometrias se sobrepõem.
Caso 1:
SELECT ST_Overlaps(
ST_GeomFromText( 'LINESTRING( 4 8, 7 8 )' ),
ST_GeomFromText( 'LINESTRING( 5 6, 5 9 )' )
);
Caso 2:
SELECT ST_Overlaps(
ST_GeomFromText( 'LINESTRING( 8 8, 12 8 )' ),
ST_GeomFromText( 'LINESTRING( 9 6, 9 8, 11 8, 11 9 )' )
);
Caso 3:
SELECT ST_Overlaps(
ST_GeomFromText( 'POLYGON( ( 1 1, 1 3, 4 3, 4 1, 1 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 4 2, 4 4, 6 4, 6 2, 4 2 ) )' )
);
Caso 4:
SELECT ST_Overlaps(
ST_GeomFromText( 'POLYGON( ( 7 1, 7 3, 10 3, 10 1, 7 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 9 2, 13 4, 13 1, 9 2 ) )' )
);
3.4.6.8. ST_Disjoint
O relacionamento espacial ST_Disjoint
diz se duas geometrias são disjuntas, isto é, se elas não possuem nenhuma interação espacial.
Caso 1:
SELECT ST_Disjoint(
ST_GeomFromText( 'LINESTRING( 1.5 5, 3 5, 4 6, 6 5 )' ),
ST_GeomFromText( 'LINESTRING( 1 6, 1 4, 4 4 )' )
);
Caso 2:
SELECT ST_Disjoint(
ST_GeomFromText( 'POLYGON( ( 1 1, 1 2, 3 2, 3 1, 1 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 3 3, 5 3, 5 2, 3 2, 3 3 ) )' )
);
3.4.6.9. ST_Intersects
O relacionamento espacial ST_Intersects
diz se a geometria A
possui algum tipo de interação espacial com a geometria B
.
Caso 1:
SELECT ST_Intersects(
ST_GeomFromText( 'POLYGON( ( 1 7, 1 9, 5 9, 5 7, 1 7 ) )' ),
ST_GeomFromText( 'POLYGON( ( 4 6, 4 8, 8 8, 8 6, 4 6 ) )' )
);
Caso 2:
SELECT ST_Intersects(
ST_GeomFromText( 'POLYGON( ( 10 6, 10 8, 12 8, 12 6, 10 6 ) )' ),
ST_GeomFromText( 'POLYGON( ( 12 6, 12 8, 14 8, 14 6, 12 6 ) )' )
);
Caso 3:
SELECT ST_Intersects(
ST_GeomFromText( 'POLYGON( ( 1 1, 1 5, 5 5, 5 1, 1 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 2 2, 2 4, 4 4, 4 2, 2 2 ) )' )
);
Caso 4:
SELECT ST_Intersects(
ST_GeomFromText( 'POLYGON( ( 6 1, 6 5, 10 5, 10 1, 6 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 7 3, 7 5, 9 5, 9 3, 7 3 ) )' )
);
Caso 5:
SELECT ST_Intersects(
ST_GeomFromText( 'POLYGON( ( 11 1, 11 3, 13 3, 13 1, 11 1 ) )' ),
ST_GeomFromText( 'POLYGON( ( 13 3, 13 5, 15 5, 15 3, 13 3 ) )' )
);