Spatial Joins

Database/PostGIS 2009. 12. 29. 14:54

공간조인(Spatial join)은 공간데이터베이스(spatial database)와 뗄 수 없는 관계이다. 이번 섹션은 관계 연산자(relation operator)와 약간의 일반적인 사용 예제를 서론으로 제공한다.

공간조인은 두 개 혹은 그 이상의 데이터셋을 공간 릴레이션(spatial relationship)과 관련하여 조합하기 위한 연산이다.

(medford_citylimits)Medford city 에 한정된 jacksonco_schools 테이블의 학교 목록을 얻기 위해서는 다음과 같은 쿼리를 사용할 것이다:

이 쿼리는 각각의 학교가 도시 경계 폴리곤 안에 있는 없는지 확인한다. ST_Within 함수는 각각의 학교가 도시 경계 폴리곤 안에 완전하게 있는지 확인하는 꽤 엄격한 정의를 가지고 있다. 이것은 학교가 경계선에 있으면 기술적으로 폴리곤 안에 있지 않는 것을 의미한다. 이것은 폴리곤과 선을 비교할 때 매우 흥미롭게 한다. 선의 끝점이 경계영역의 에 위치하게 되거나, 선의 일부분이 경계영역에 접하게 되는 것은 false 값을 갖게 됨에 충분하다. ST_Within 함수는 바운딩 박스(bounding box) 중첩 연산자(overlap operator: &&)를 포함하고 있음을 명심하여라.

다음으로는 ST_Length 함수를 이용하여 Medford 도시 도로의 총 길이를 계산해 본다. 우리는 ST_Within 연산자를 한번 더 사용할 수도 있지만, 이것은 완벽하게 포함되었는지 판단하는 요청으로 도로의 길이를 더 짧게 계산할 수도 있다. 차라리 ST_Intersects를 사용하여 도로의 길이를 더 길게 계산하여 본다.

이번에는 공간데이터를 다른 데이터들과 함께 사용해 본다. race 테이블은 인구통계치를 tracts 테이블에 있는 인종에 따라 분석해 놓았다. Jackson Country의 각각의 학교마다 인종별 비율을 결정해 보자.

이번에는 릴레이션 연산자의 성능과 유연성을 볼 차례이다.

Note
인구수는 integer로 저장되기 때문에, 우리는 decimal로 계산하기 위해서 floating 포인트로 변환을 하였다. 이것은 CAST white_pop_1race AS DOUBLE PRECSION과 같이 형변환을 하는 것과 같이 많은 방법으로 수행될 수 있다. 나는 위에서 decimal 값(1.0)을 사용하므로써 변환을 하였다.

아래는 릴레이션 연산자와 그에 대한 짧은 설명이다. 각각의 함수들은 참(true) 혹은 거짓(false) 값을반환할 것이다. 나중 섹션에서 이 함수들을 이용하여 더 좋은 사례를 보여줄 것이다. 이 함수들에 대한 완벽한 설명을 보려면 PostGIS 문서를 참조하여라[1].

ST_Contains(A, B)

Returns true if no points in B lie outside of A, and the interiors of A and B share at least one point, otherwise false.

ST_ContainsProperly(A, B)

Returns true if B intersects the interior of A but not the boundary, otherwise false.

ST_Covers(A, B)

Returns true if no point in B is outside of A, otherwise false.

ST_CoveredBy(A, B)

Returns true if no point in A is outside of B, otherwise false.

ST_Crosses(A, B)

Returns true if A and B share some but not all points in common, otherwise false.

ST_Disjoint(A, B)

Returns true if there are no points in common between A and B, otherwise false.

ST_Intersects(A, B)

Returns true if there are any points in common between A and B, otherwise false.

ST_Overlaps(A, B)

Returns true if the geometries intersect, but are not contained and are of the same dimension (i.e. both lines, both points or both polygons), otherwise false.

ST_Touches(A, B)

Returns true if A and B have at least one point in common but their interiors don't overlap, otherwise false.

ST_Within(A, B)

Returns true if A is completely inside B, otherwise false.

Posted by 강부자아들
,