官术网_书友最值得收藏!

  • QGIS 2 Cookbook
  • Alex Mandel Víctor Olaya Ferrero Anita Graser Alexander Bruy
  • 420字
  • 2021-07-16 11:12:40

Configuring relations

In the Joining layer data recipe, we discussed that joins only append additional columns to existing features (1:1 or n:1 relationships). Using joins, it is, therefore, not possible to model 1:n relationships, such as "one zip code area containing n schools". These kinds of relationships can instead be modeled using relations. This recipe introduces the concept of relations and shows how you can put them to use.

Getting ready

To follow this exercise, load zip code areas and schools from zipcodes_wake.shp and schools_wake.shp.

How to do it…

Relations are configured in Project Properties. The dialog is very similar to the join dialog:

  1. Define the two layers (Referencing/Child and Referenced/Parent), as well as the fields containing the common values/IDs. As you want to model "one zip code area contains n schools," the zip code dataset is the parent layer and the school dataset is the child layer. The connection between both datasets is established based on the zip code fields (ADDRZIPCOD and ZIPNUM), as shown in the following screenshot:
    How to do it…
  2. To verify that the relation is set up and working, you can either check the attribute table in form view (button in the lower-right corner), as shown in the following screenshot, or open an individual feature form. You will find that the relation information has been appended at the end of the form:
    How to do it…

    As the preceding screenshot shows, setting up this relation enables you to get access to all schools within a certain zip code in a very convenient way. As the edit button suggests, it is even possible to edit the school data from this view. You can simply edit the values in the table view. You can add and delete schools from the dataset using the + and X buttons. The next two buttons enable you to quickly add new entries to the relation or to remove them.

How it works…

In this example, removing a school from the dataset works just fine, but adding a school via this dialog makes less sense because you cannot create a point geometry through this process.

If you press the button to add to the relation, you will get a dialog that allows you to choose which existing school you want to add. In the background, the school's ADDRZIPCOD value is updated to match the zip code we just assigned it to.

Similarly, if you select a school and press the button to remove the relation, what actually happens is that the school's ADDRZIPCOD value is set to NULL.

主站蜘蛛池模板: 绥化市| 沿河| 宽城| 宝山区| 漳浦县| 孝感市| 溆浦县| 中山市| 西华县| 阳高县| 布尔津县| 元谋县| 宿州市| 精河县| 岳普湖县| 古田县| 兴文县| 忻城县| 济阳县| 正宁县| 兴海县| 湾仔区| 界首市| 邵东县| 临朐县| 壤塘县| 宜兴市| 深水埗区| 和静县| 咸阳市| 北辰区| 缙云县| 福海县| 平江县| 土默特左旗| 阳江市| 吉林市| 雷波县| 荆州市| 革吉县| 阳曲县|