테이블 결합 작업

경고

This tutorial is now obsolete. A new and updated version is available at 테이블 결합 작업(QGIS3)

사용하고자 하는 모든 데이터셋이 shapefile 혹은 공간데이터 형태이지는 않습니다. 종종 데이터는 테이블 또는 스프레드쉬트 이고 분석에 사용할 기존 공간 데이터에 연결할 필요가 있습니다. 이 작업이 테이블 결합 `Table Join`으로 알려져 있고 이 예제에서는 QGIS에서 어떻게 테이블 결합을 하는지 알려줍니다.

과업 개요

캘리포니아의 인구지도를 만들기 위해 미국통계국 US Census Bureau로부터 인구데이터 표와 캘리포니아의 센서스 트랙 shapefile을 사용합니다.

기타 스킬

  • CSV파일에서 열 데이터를 나타내기 위해 .csvt 파일을 만듭니다.

  • QGIS에서 어떠한 기하학적 내용도 포함되지 않은 CSV파일을 불러옵니다.

데이터 획득

US Census Bureau has various spatial extracts from the MAF/TIGER database. You can query and download census tracts shapefile for California. Download Census Tracts for California file.

`Americal FactFinder <http://factfinder2.census.gov/faces/nav/jsf/pages/searchresults.xhtml?refresh=t>`_는 미국의 모든 센서스 데이터의 저장소입니다. `Advanced Search`를 사용할 수 있고 원하는 CSV를 만들고 다운로드 하기 위해 `Topic - Total Population`와 `Geographies - All Census Tracts in California`를 조회할 수 있습니다. 이 예제에서는 `Total Population 2010 Census Summary File 1`을 사용합니다.

For convenience, you may directly download a copy of both the datasets from the links below:

tl_2013_06_tract.zip

ca_tracts_pop.csv

데이터 출처 [TIGER] [USCENSUS]

과정

  1. 처음에는 센서스 트랙 shapefile을 불러옵니다. 메뉴 레이어 –> 벡터 레이어 추가 :menuselection:`Layer –> Add Vector Layer`로 갑니다.

../_images/1200.png
  1. Browse to the downloaded zip file tl_2013_06_tract.zip and select it. QGIS can open zip files directly so no need to uncompress it first.

../_images/2164.png
  1. Select the tl_2013_06_tract.shp layer and click OK.

../_images/3103.png
  1. QGIS로 센서스 트랙이 불러들여집니다.

../_images/466.png
  1. 레이어를 오른쪽 클릭하고 속성 테이블 열기 :guilabel:`Open Attribute Table`를 선택합니다.

../_images/560.png
  1. 트랙 shapefile의 속성을 살펴보십시오. 이 shapefile에 테이블을 결합하기 위해서는 각 객체의 유일하고 일반적인 속성이 필요합니다. 이 경우에는 **GEOID**필드가 각 트랙에서 유일한 구분자이고 같은 ID를 포함하고 있는 다른 테이블과 이 shapefile을 ‘결합’ 할 수 있습니다.

../_images/658.png
  1. Open the CSV file ca_tracts_pop.csv in a text editor. You will notice that each row of the file contains information about a tract along with the unique identifier we saw in the previous step. Note that this field is called GEO.id2 in the CSV. You will also note that the D001 column has population value for each of the census tract.

../_images/757.png
  1. We could import this csv file without any further action and it would be imported. But, the default type of each column would be a String (text). That is ok except for the D001 field which contains numbers for the population. Having those imported as text would not allow us to run any mathematical operations on this column. To tell QGIS to import the field as a number, we need to create a sidecar file with a .csvt extension. This file will have only 1 row specifying data types for each column. Save this file as ca_tracts_pop.csvt in the same directory as the original .csv file. You can also download the csvt file from here.

../_images/855.png
  1. 이제 QGIS에 CSV파일을 불러들일 준비가 되었습니다. 메뉴 레이어 –> 구분자로 분리된 텍스트 레이어를 추가 :menuselection:`Layer –> Add Delimited Text Layer`로 갑니다.

../_images/954.png
  1. CSV파일을 포함하고 있는 폴더를 찾아서 선택합니다. 파일 포맷 :guilabel:`File format`을 :guilabel:`CSV (comma separated values)`로 선택했는지 확인합니다. 표로 이 파일을 불러들이기 때문에 파일에 지오메트리가 아님을 반드시 확인해야 합니다. 지오메트리가 아님 :guilabel:`No geometry (attribute only table)`옵션을 선택합니다. :guilabel:`OK`를 클릭합니다.

../_images/1062.png
  1. CSV가 표로 QGiS에 불러들여 질 것입니다.

../_images/11101.png
  1. Select the tl_2013_06_tract layer. Right-click on it and select Properties.

../_images/1264.png
  1. 레이어 속성 Layer Properties 다이알로그에서 결합 Joins 탭을 선택합니다. 새로운 표를 결합시키기 위해서 아랫쪽에 + 단추를 클릭합니다.

../_images/1361.png
  1. In the Add vector join dialog, select ca_tracts_pop as the Join layer. Next we have to select the field with unique ids in both the shapefile and the CSV. Select GEO.id2 and GEOID as the Join field and Target field respectively. Click OK.

../_images/1458.png
  1. Close the Layer Properties dialog and return to the main QGIS window. At this point, the fields from the CSV file are joined with the shapefile. Right-click on the tl_2013_06_tract layer and select Open Attribute Table.

../_images/1553.png
  1. 이제 ca_tracts_pop_D001 필드가 각 객체에 포함된 새로운 필드를 볼 수 있습니다. 이제 CSV파일로부터 각 트랙의 인구값에 접근합니다. 속성 테이블을 닫고 QGIS로 돌아갑니다.

../_images/1650.png
  1. Right-click the tl_2013_06_tract layer and select Properties.

../_images/1747.png
  1. 스타일 Style 탭을 선택합니다. 드롭다운 메뉴에서 단계로 나누어진 :guilabel:`Graduated`을 선택합니다. 인구지도를 만들려고 하는 것처럼 인구수를 바탕으로 각 센터스 트랙 객체에 다른 색깔을 지정합니다. 컬럼 :guilabel:`Column`에 :guilabel:`ca_tracts_pop_D001`를 선택합니다. 색상표 :guilabel:`Color ramp`를 드롭다운하여 선호하는 색계열을 선택합니다. 모드 :guilabel:`Mode`에서 분위수동일갯수 :guilabel:`Quantile (Equal Count)`를 선택합니다. 다음 분류 :guilabel:`Classify`를 클릭합니다. 인구수 범위에 따라 다른 색이 지정된 것을 볼 수 있습니다. :guilabel:`OK`를 클릭합니다.

../_images/1844.png
  1. 이제 인구수를 이용하여 시각적으로 멋있는 센서스 트랙을 볼 수 있습니다. 레이어의 보다 작은 부분을 선택하기 위해 확대 :guilabel:`Zoom in`툴을 이용합니다.

../_images/1935.png
  1. 캘리포니아의 상세하고 정확한 인구지도가 만들어 졌습니다. 다양한 센서스 데이터를 토대로 지도를 만들기 위하여 몇몇 기법을 사용할 수 있습니다.

../_images/2030.png

If you want to give feedback or share your experience with this tutorial, please comment below. (requires GitHub account)