Spatial Topologies Analysis
🌍 Advanced Geospatial Analysis
This program implements and verifies three fundamental operations that apply to the eleven region-region relations R in S2 as defined in Point-Set Topological Spatial Relations: converse (conv), leftDual (ld), and rightDual (rd).
Repository: https://github.com/ecorey/Spatial-Topologies
The spatial relations are represented as 3x3 intersection matrices in S2 space:
embrace
[[1, 1, 1], [1, 0, 0], [1, 0, 0]]
attach
[[0, 0, 1], [0, 1, 0], [1, 0, 0]]
disjoin
[[0, 0, 1], [0, 0, 1], [1, 1, 1]]
entwined
[[1, 1, 1], [1, 1, 0], [1, 0, 0]]
meet
[[0, 0, 1], [0, 1, 1], [1, 1, 1]]
overlap
[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
coveredBy
[[1, 0, 0], [1, 1, 0], [1, 1, 1]]
covers
[[1, 1, 1], [0, 1, 1], [0, 0, 1]]
inside
[[1, 0, 0], [1, 0, 0], [1, 1, 1]]
equals
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
contains
[[1, 1, 1], [0, 0, 1], [0, 0, 1]]
Fundamental Operations
Three fundamental operations apply to all eleven region-region relations in S2 space:
converse (conv)
Reverses the spatial relationship by transposing the intersection matrix.
- • Swaps matrix elements across the diagonal
- • Effectively reverses the direction of the spatial relationship
- • Symmetrical matrices return unchanged
leftDual (ld)
Applies left dual transformation by swapping the first and third rows.
- • Exchanges row[0] with row[2]
- • Preserves middle row structure
- • Creates complementary spatial relationship
rightDual (rd)
Applies right dual transformation by swapping the first and third columns.
- • Exchanges column[0] with column[2]
- • Preserves middle column structure
- • Creates complementary spatial relationship
Verification Tests
The program verifies six fundamental equivalence relationships between operations:
Primary Equivalence Tests
Extended Equivalence Tests
Code Implementation
Left Dual Operation
Swaps the first and third rows of the intersection matrix:
def lft_dual(matrix): """Returns the left dual of a given matrix.""" temp = [0, 0, 0] temp[0] = matrix[0][0] temp[1] = matrix[0][1] temp[2] = matrix[0][2] matrix[0][0] = matrix[2][0] matrix[0][1] = matrix[2][1] matrix[0][2] = matrix[2][2] matrix[2][0] = temp[0] matrix[2][1] = temp[1] matrix[2][2] = temp[2] return matrix
Right Dual Operation
Swaps the first and third columns of the intersection matrix:
def rt_dual(matrix): """Returns the right dual of a given matrix.""" temp = [0, 0, 0] temp[0] = matrix[0][0] temp[1] = matrix[1][0] temp[2] = matrix[2][0] matrix[0][0] = matrix[0][2] matrix[1][0] = matrix[1][2] matrix[2][0] = matrix[2][2] matrix[0][2] = temp[0] matrix[1][2] = temp[1] matrix[2][2] = temp[2] return matrix
Converse Operation
Transposes the intersection matrix to reverse the spatial relationship:
def converse(matrix): """Returns the converse of a given matrix.""" if (matrix[1][0] == matrix[0][1]) and (matrix[2][0] == matrix[0][2]) and (matrix[2][1] == matrix[1][2]): # symmetrical matrices will return the matrix return matrix elif (matrix[1][0] != matrix[0][1]) and (matrix[2][0] != matrix[0][2]) and (matrix[2][1] != matrix[1][2]): # converse matrices will return the converse matrix temp = [0, 0, 0] temp[0] = matrix[0][1] temp[1] = matrix[0][2] temp[2] = matrix[1][2] matrix[0][1] = matrix[1][0] matrix[0][2] = matrix[2][0] matrix[1][2] = matrix[2][1] matrix[1][0] = temp[0] matrix[2][0] = temp[1] matrix[2][1] = temp[2] return matrix
Installation & Setup
Prerequisites
- • Python: Version 3.6 or later
- • NumPy: For matrix operations (optional but recommended)
- • Git: For repository management
Clone Repository
git clone https://github.com/ecorey/Spatial-Topologies.git cd Spatial-Topologies
Install Dependencies (Optional)
pip install numpy # For enhanced matrix operations
Usage Examples
Basic Operation Example
Testing Spatial Relationship Operations
# Define a spatial relation matrix (example: "embrace") embrace_matrix = [[1, 1, 1], [1, 0, 0], [1, 0, 0]] # Apply operations left_dual_result = lft_dual(embrace_matrix.copy()) right_dual_result = rt_dual(embrace_matrix.copy()) converse_result = converse(embrace_matrix.copy()) print("Original:", embrace_matrix) print("Left Dual:", left_dual_result) print("Right Dual:", right_dual_result) print("Converse:", converse_result)
Verification Testing
Testing Equivalence Relationships
# Test equivalence: conv(ld(R)) ≡ ld(conv(R)) original = [[1, 1, 1], [1, 0, 0], [1, 0, 0]] # Left path: conv(ld(R)) left_path = converse(lft_dual(original.copy())) # Right path: ld(conv(R)) right_path = lft_dual(converse(original.copy())) # Verify equivalence if left_path == right_path: print("✅ Equivalence test passed!") else: print("❌ Equivalence test failed!")
💡 Key Features
- • Exhaustively verifies six fundamental equivalence relationships
- • Implements all eleven region-region spatial relations in S2
- • Tests converse, left dual, and right dual operations
- • Validates matrix transformation equivalences
- • Demonstrates point-set topological spatial relations theory