Выполнение пространственных присоединений


This tutorial is now obsolete. A new and updated version is available at Performing Spatial Joins (QGIS3)

Пространственное соединение - это классическая задача ГИС: передача атрибутов от одного слоя к другому в зависимости от их пространственного отношения. В QGIS эта функциональность доступна с помощью инструмента Join Attributes by Location.

Обзор задачи

Мы будем использовать 2 слоя: shape-файл границ районов города Нью-Йорк и другой shape-файл с расположением домов престарелых в Нью-Йорке. Мы будем использовать методику пространственного присоединения, чтобы найти общую вместимость домов престарелых для каждого из районов.

Вы научитесь также

  • удалять столбцы из таблицы атрибутов слоя.

Получение данных

NYC Open Data Portal is an excellent source of free data for New York city.

  1. Download the Borough Boundaries zip file using the Export option on the portal.
  1. Download the Nursing Homes zip file using the Export option on the portal.

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




  1. Go to Layer ‣ Add Vector Layer. Browse to the downloaded zip file nybb_12c.zip and select Open.
  1. Выберите слой nybb.shp и нажмите OK.

  1. Repeat the steps 3 and 4 for the another file OEM_NursingHomes_001.zip and load the OEM_NursingHomes_001.shp layer. Once both the layers are loaded, right-click on the OEM_NursingHomes_001 layer and select Open Attribute Table.
  1. Examine the attributes available for each feature. Since our task is to calculate the total nursing home capacity for each borough, we can use the attribute Capacity which can join to the boundaries layer.
  1. Go to Vector ‣ Data Mangement Tools ‣ Join attributes by location.
  1. The Target vector layer is the one we want to add the attributes to. In our case, this will be the boroughs boundary nybb layer. The Join vector layer will be the nursing homes OEM_NursingHomes_001 layer. As we want to sum the capacity of nursing homes, select Take summary of intersecting features and choose Sum. Name the output file as nyc_borough_join.shp. In the Output table select Keep all records`.
  1. Once the process finishes, select Yes when asked if you want to add the layer to TOC. The new layer nyc_borough_join would have the features from nybb layer along with spatially joined attributes from OEM_NursingHomes_001 layer. Right-click on the layer and select Open Attribute Table.
  1. You will see a column SUMCapacit in the attribute table. This is the sum of the Capacity attribute for the nursing homes that fall within each borough feature.
  1. This is the answer we are looking for. But there are extra columns that we do not need in our output. Let’s clean up our output. Click on the Toggle editing button and then the Delete column button.
  1. Press Control-A to select all columns in the Delete Attributes dialog. Next hold the Control key and de-select the columns you want to keep. Click OK.
  1. In the attribute table, click Toggle editing button again to save the changes.
  1. Back in the QGIS Canvas, use the Identify tool to verify that the output file has the desired attributes for each burough feature.
If you liked tutorials on this site and do check out spatialthoughts.com for more free resources.
comments powered by Disqus

This work is licensed under a Creative Commons Attribution 4.0 International License