{"id":13455,"date":"2022-11-29T07:37:00","date_gmt":"2022-11-29T06:37:00","guid":{"rendered":"https:\/\/www.opengis.ch\/?p=13455"},"modified":"2022-11-28T19:41:32","modified_gmt":"2022-11-28T18:41:32","slug":"qgis-relations-their-widgets-and-the-plugins-of-them","status":"publish","type":"post","link":"https:\/\/www.opengis.ch\/de\/2022\/11\/29\/qgis-relations-their-widgets-and-the-plugins-of-them\/","title":{"rendered":"QGIS Relations, their Widgets and the Plugins of them"},"content":{"rendered":"\n<p><em><strong>This blog post is about QGIS relations and how they are edited in the attribute form with widgets in general, as well as some plugins that override the relations editor widget to improve usability and solve specific use cases. The start is quite basic. If you are already a relation hero, then <a href=\"#plugins\" data-type=\"internal\" data-id=\"#plugins\">jump directly to the plugins<\/a>.<\/strong><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"qgis-relations\">QGIS Relations in General<\/h2>\n\n\n\n<p>Let&#8217;s have a look at a simple example data model. We have four entities: Building, Apartment, Address and Owner. In UML it looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"346\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?resize=750%2C346&#038;ssl=1\" alt=\"\" class=\"wp-image-13466\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?resize=1024%2C472&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?resize=300%2C138&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?resize=768%2C354&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?resize=469%2C216&amp;ssl=1 469w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?resize=1536%2C708&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/erm.png?w=1893&amp;ssl=1 1893w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>A building can have none or multiple apartments, but an apartment must to be related to a building. This black box on the left describes the relation strength as a composition. An apartment cannot exist without a building. When a building is demolished, all apartments of it are demolished as well.<\/li><li>An apartment needs to be owned by at least one owner. An owner can own none or more apartments. This is a many-to-many relation and this means, it will be normalized by adding a linking (join) table in between.<\/li><li>A building can have an address (only one &#8211; no multiple entrances in this example). An address can refer to one building. <br>Why not making one single table on a one-to-one relation? To ensure their existence independently: When a building is demolished, the address should persist until the new building is constructed.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-relations-in-qgis\">Creating Relations in QGIS<\/h3>\n\n\n\n<p>In QGIS we have now five layers. The four entities and the linking table called &#8222;Apartment_Owner&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"339\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/layers.png?resize=750%2C339&#038;ssl=1\" alt=\"\" class=\"wp-image-13467\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/layers.png?w=878&amp;ssl=1 878w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/layers.png?resize=300%2C136&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/layers.png?resize=768%2C347&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/layers.png?resize=500%2C226&amp;ssl=1 500w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/layers.png?resize=469%2C212&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>Open&nbsp;<em>Project &gt; Properties&#8230; &gt; Relations<\/em><\/p>\n\n\n\n<p>With&nbsp;<em>Discover Relations<\/em>&nbsp;the possible relations are detected from the existing layers according to their foreign keys in the database. In this example no CASCADE is defined in the database what means that the relations strength is always &#8222;Association&#8220;.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"where-would-composition-make-sense\">Where would &#8222;Composition&#8220; make sense?<\/h4>\n\n\n\n<p>Of course in the relation &#8222;Apartment&#8220; to &#8222;Building&#8220;, to ensure that when a feature of &#8222;Building&#8220; is deleted, the children (&#8222;Apartment&#8220;) are deleted as well, because they cannot exist without a building. Also a&nbsp;<em>duplication<\/em>&nbsp;of a feature of &#8222;Building&#8220; would duplicate the children (&#8222;Apartment&#8220;) as well.<\/p>\n\n\n\n<p>But as well on the linking (join) table &#8222;Apartment_Owner&#8220; and its relation to &#8222;Apartment&#8220; and &#8222;Owner&#8220; a composition would make sense. Because when a feature of &#8222;Apartment&#8220; or &#8222;Owner&#8220; is deleted, the entry in the linking table should be deleted as well. Because this connection does not exist anymore and otherwise this would lead to orphan entries in the linking table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"walk-through-the-widgets\">Walk through the widgets<\/h3>\n\n\n\n<p>To demonstrate the relation widgets&nbsp;<em>Relation Editor<\/em>,&nbsp;<em>Relation Reference<\/em>&nbsp;and&nbsp;<em>Value Relation<\/em>&nbsp;we make a walk through the digitizing process.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"relation-editor\">Relation Editor<\/h4>\n\n\n\n<p>First we create a &#8222;Building&#8220; and call it &#8222;Garden Tower&#8220;. Then we add some &#8222;Apartments&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"378\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor.png?resize=750%2C378&#038;ssl=1\" alt=\"\" class=\"wp-image-13468\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor.png?w=1017&amp;ssl=1 1017w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor.png?resize=300%2C151&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor.png?resize=768%2C387&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor.png?resize=469%2C236&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>The &#8222;Apartments&#8220; are created in the widget called&nbsp;Relation Editor. This shows us a list (similar to the <em>QGIS Attribute Table<\/em>) of all children (&#8222;Apartment&#8220;) referencing to this &#8222;Building&#8220;. We have here activated the possibilities to&nbsp;<em>add<\/em>,&nbsp;<em>delete<\/em>&nbsp;and&nbsp;<em>duplicate<\/em>&nbsp;child-features.<\/p>\n\n\n\n<p>In the widget settings (<em>Right-click on the layer &gt; Properties&#8230; &gt; Attribute Form<\/em>) we see that there are other possibilities to&nbsp;<em>link<\/em>&nbsp;and&nbsp;<em>unlink<\/em>&nbsp;child-features as well as&nbsp;<em>zoom<\/em>&nbsp;to the current child-feature (what only would make sense when they have a geometry).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"330\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_settings.png?resize=750%2C330&#038;ssl=1\" alt=\"\" class=\"wp-image-13469\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_settings.png?resize=1024%2C450&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_settings.png?resize=300%2C132&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_settings.png?resize=768%2C337&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_settings.png?resize=469%2C206&amp;ssl=1 469w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_settings.png?w=1077&amp;ssl=1 1077w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>As well we can set here the cardinality. This will become interesting when we go to the &#8222;Owner&#8220; to &#8222;Apartment&#8220; relation. But let&#8217;s first have a look at the opposite of what we just did.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"relation-reference\">Relation Reference<\/h4>\n\n\n\n<p>When we open now a feature of &#8222;Apartment&#8220;, we see that we have a drop down to select the &#8222;Building&#8220; to reference to.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"113\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationreference.png?resize=720%2C113&#038;ssl=1\" alt=\"\" class=\"wp-image-13470\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationreference.png?w=720&amp;ssl=1 720w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationreference.png?resize=300%2C47&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationreference.png?resize=469%2C74&amp;ssl=1 469w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/figure>\n\n\n\n<p>On the right of this drop down we can see some buttons. Those are for the following functionalities (from left to right):<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open the form of the current parent feature (in our case the &#8222;Building&#8220; feature called &#8222;Garden Tower&#8220;)<\/li><li>Add a new feature on the parent layer (in our case &#8222;Building&#8220;)<\/li><li>Highlight the parent layer (in our case &#8222;Building&#8220;) on the map<\/li><li>Select the parent feature (in our case &#8222;Building&#8220;) on the map to reference it<\/li><\/ul>\n\n\n\n<p>In the settings (<em>Right-click on the layer &gt; Properties&#8230; &gt; Attribute Form<\/em>) we see that we choose the configured relation to connect the child (&#8222;Apartment&#8220;) to the parent (&#8222;Building&#8220;). This won&#8217;t be needed with the widget&nbsp;<em>Value Relation<\/em>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"value-relation\">Value Relation<\/h4>\n\n\n\n<p>The&nbsp;<em>Value Relation<\/em>&nbsp;does not require a relation at all. We simply choose the &#8222;parent&#8220; layer (&#8222;Building&#8220;) its primary key as the key (&#8222;t_id&#8220;) and a descriptive field as the value (&#8222;Description&#8220;).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"150\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation_settings.png?resize=750%2C150&#038;ssl=1\" alt=\"\" class=\"wp-image-13471\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation_settings.png?w=808&amp;ssl=1 808w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation_settings.png?resize=300%2C60&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation_settings.png?resize=768%2C154&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation_settings.png?resize=469%2C94&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>The result shows us a drop down as well to select the parent.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"103\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation.png?resize=720%2C103&#038;ssl=1\" alt=\"\" class=\"wp-image-13472\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation.png?w=720&amp;ssl=1 720w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation.png?resize=300%2C43&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/valuerelation.png?resize=469%2C67&amp;ssl=1 469w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/figure>\n\n\n\n<p>It is much easier to configure, but you can see the limitations. There are no such functionalities to control the parent feature like&nbsp;<em>add<\/em>,&nbsp;<em>identify on map<\/em>&nbsp;etc. As well you need to be careful to fulfill the foreign key constraint (you have to choose the correct field to link with). All this is given, when you build a&nbsp;<em>Relation Reference<\/em>&nbsp;on an existing relation.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"many-to-many-relations\">Many-to-Many Relations<\/h4>\n\n\n\n<p>Now we link some &#8222;Owner&#8220; to our &#8222;Apartment&#8220;. We could create new ones like we did it for the &#8222;Apartment&#8220; in &#8222;Building&#8220; or we can&nbsp;<em>link<\/em>&nbsp;existing ones. For linking we choose the yellow link-button on the top of the&nbsp;<em>Relation Editor<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"278\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/linking_dialog.png?resize=750%2C278&#038;ssl=1\" alt=\"\" class=\"wp-image-13473\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/linking_dialog.png?w=857&amp;ssl=1 857w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/linking_dialog.png?resize=300%2C111&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/linking_dialog.png?resize=768%2C285&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/linking_dialog.png?resize=469%2C174&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>This dialog looks similar to the&nbsp;<em>Relation Editor<\/em>&nbsp;widget. You have just to select the &#8222;Owner&#8220; you want to link to the &#8222;Apartment&#8220; by checking the yellow box. It&#8217;s a very powerful tool, but people are often confused about the load of functionality here and the selection that can be difficult to get used to (yellow boxes vs. blue index selection). For this case we extended the&nbsp;<em>Relation Editor<\/em>&nbsp;widget with a <a href=\"#linkingrelationeditor\" data-type=\"internal\" data-id=\"#linkingrelationeditor\">plugin<\/a>.<\/p>\n\n\n\n<p>Anyway after that we linked our features of the layer &#8222;Owner&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"186\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_many.png?resize=750%2C186&#038;ssl=1\" alt=\"\" class=\"wp-image-13474\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_many.png?w=816&amp;ssl=1 816w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_many.png?resize=300%2C74&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_many.png?resize=768%2C190&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/relationeditor_many.png?resize=469%2C116&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>Have you seen the linking table in between? Well, me neither. It&#8217;s completely invisible for the end user. This because of the cardinality setting I mentioned already. When we choose the linked table &#8222;Owner&#8220; instead of &#8222;Many to one relation&#8220;, then we can create and link the other parent (&#8222;Owner&#8220;) directly.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"one-to-one-relation\">One-to-One Relation<\/h4>\n\n\n\n<p>A one-to-one relation like we have here between &#8222;Building&#8220; and &#8222;Address&#8220; is created in the database more or less like a normal one-to-many relation. This means one of the tables (in our case &#8222;Address&#8220;) has a foreign key pointing to the parent table (&#8222;Building&#8220;). There are tricks to fulfill the one-to-one maximum cardinality (like e.g. by setting a UNIQUE constraint on this foreign key column) but still in the QGIS user interface it looks like a one-to-many relation. It&#8217;s displayed in a normal&nbsp;<em>Relation Editor<\/em>&nbsp;widget.<\/p>\n\n\n\n<p>Solutions could be so called &#8222;Joins&#8220;. Go to the settings (<em>Right-click on the layer &gt; Properties&#8230; &gt; Joins<\/em>)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"264\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins_settings.png?resize=750%2C264&#038;ssl=1\" alt=\"\" class=\"wp-image-13475\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins_settings.png?w=855&amp;ssl=1 855w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins_settings.png?resize=300%2C106&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins_settings.png?resize=768%2C270&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins_settings.png?resize=469%2C165&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>Here you can join a layer of your choice and add the fields of this other layer (in our case &#8222;Address&#8220;) to your current feature form (of &#8222;Building&#8220;). So it appears to the user that it&#8217;s the same table containing fields of &#8222;Building&#8220; and &#8222;Address&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"222\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins.png?resize=750%2C222&#038;ssl=1\" alt=\"\" class=\"wp-image-13476\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins.png?w=1002&amp;ssl=1 1002w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins.png?resize=300%2C89&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins.png?resize=768%2C227&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/joins.png?resize=469%2C139&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>Negative point about those joins are, that they are fault prone. You have to be careful with default values (e.g. on primary keys) of the joined layer. You cannot expect a fully reliable feature form like you have it in the&nbsp;<em>Relation Editor<\/em>. Here as well, we extended the&nbsp;<em>Relation Editor<\/em>&nbsp;widget with a <a href=\"#linkingrelationeditor\" data-type=\"internal\" data-id=\"#linkingrelationeditor\">plugin<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"plugins\">Plugins for Relation Editor Widgets<\/h2>\n\n\n\n<p>Since QGIS 3.18 the base class of the <em>Relation Editor Widgets <\/em>became abstract, what opened the possibility to use it in PyQGIS and derive it to super nice widgets handling specific use cases and improving the usability.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"linkingrelationeditor\">Linking Relation Editor Widget<\/h3>\n\n\n\n<p>As mentioned before, the QGIS stock dialog to link children is full of features but it can be overwhelming and difficult to use. Mostly because of the two selection possibilities in the list. A blue selection is for the currently displayed feature, and a yellow checkbox selection is for the features to be actually linked.<\/p>\n\n\n\n<p>In collaboration with the Model Baker Group we wanted to improve the situation. But as we where unsure how the end solution should look like, so we decided to experiment in a plugin. The result is a<em> link manger dialog,<\/em> in which features can be <em>linked<\/em> and <em>unlinked<\/em> by moving them left and right. The effective link is created or destroyed when the dialog is accepted.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"415\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-25-13-59.gif?resize=750%2C415&#038;ssl=1\" alt=\"\" class=\"wp-image-13461\"\/><\/figure>\n\n\n\n<p>Find more information on the repository <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/opengisch\/qgis-linking-relation-editor\" target=\"_blank\">https:\/\/github.com\/opengisch\/qgis-linking-relation-editor<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ordered Relation Editor Widget<\/h3>\n\n\n\n<p>Sometimes the order of the children play a role on the project, and you want to have them displayed following that. For that there is the <em>Ordered Relation Editor Widget<\/em>. You can configure a field in the children to be used to order them. In the given example the field <em>Floor<\/em> was used to order <em>Apartments<\/em>. Reordering the fields by Drag&amp;Drop would change the value of the configured field. Display name and optionally a path to an icon to be shown on the list can be configured by expression in the <em>Attribute Form<\/em> tab in the layer properties (<em>Right-click on the layer &gt; Properties&#8230; &gt; Attribute Form<\/em>).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"364\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-25-14-08-1.gif?resize=750%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-13478\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-25-14-08-1.gif?resize=1024%2C497&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-25-14-08-1.gif?resize=300%2C146&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-25-14-08-1.gif?resize=768%2C373&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-25-14-08-1.gif?resize=469%2C228&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption>Find more information on the repository <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/opengisch\/qgis-ordered-relation-editor\" target=\"_blank\">https:\/\/github.com\/opengisch\/qgis-ordered-relation-editor<\/a><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Document Management System Widgets<\/h3>\n\n\n\n<p>Often in QGIS projects there is the need to deal with external documents. This could be for example pictures, documentations or reports about some features. To support that we added two new tables in the project:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Documents<\/strong> each document is represented by a row in this table. The table has following fields:<ul><li><strong>id<\/strong><\/li><\/ul><ul><li><strong>path<\/strong> is the filename of the document.<\/li><\/ul><\/li><li><strong>DocumentsFeatures<\/strong> this is a linking (join) table and permits to link a document with one or more features in more layers. The table has following fields:<ul><li><strong>id<\/strong><\/li><li><strong>document_id<\/strong> id of the document.<\/li><li><strong>feature_id<\/strong> id of the feature.<\/li><li><strong>feature_layer<\/strong> layer of the feature.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>Thanks to a QGIS feature named <em><a href=\"https:\/\/www.qgis.org\/en\/site\/forusers\/visualchangelog318\/index.html?highlight=polymorph#id48\">Polymorphic Relations<\/a><\/em> we can link a document with features of multiple layers. The polymorphic relation can evaluate an expression to decide in which table will be the feature to link. Here a screenshot of the relation configuration:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"95\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/image-3.png?resize=750%2C95&#038;ssl=1\" alt=\"\" class=\"wp-image-13484\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/image-3.png?w=916&amp;ssl=1 916w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/image-3.png?resize=300%2C38&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/image-3.png?resize=768%2C97&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/image-3.png?resize=469%2C59&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>After this configuration in the layers &#8222;Apartment&#8220; and &#8222;Building&#8220; it will be possible to link children from the &#8222;Documents&#8220; table. The document management plugin provides two widgets to simplify the handling of the relation. In the feature side widget the documents are displayed as a grid or list. If possible a preview of the contend is shown and you can add new documents via Drag&amp;Drop from the system file manager. <em>Double-click<\/em> on a document will open it in the default system viewer.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"364\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-27-15-25.gif?resize=750%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-13488\" srcset=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-27-15-25.gif?resize=1024%2C497&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-27-15-25.gif?resize=300%2C146&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-27-15-25.gif?resize=768%2C373&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-27-15-25.gif?resize=469%2C228&amp;ssl=1 469w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>The second widget is meant to be used in the <em>Feature Form<\/em> of the &#8222;Documents&#8220; table, and it permits to handy see, for each document, with which feature from which layer it is linked.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"458\" src=\"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/Peek-2022-11-27-15-30-1.gif?resize=750%2C458&#038;ssl=1\" alt=\"\" class=\"wp-image-13491\"\/><\/figure>\n\n\n\n<p>Find more information on the repository <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/opengisch\/qgis-document-management-system-plugin\" target=\"_blank\">https:\/\/github.com\/opengisch\/qgis-document-management-system-plugin<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">That&#8217;s it<\/h2>\n\n\n\n<p>Well then. We hope that all the beginners reading this article received some light on QGIS Relations and all the advanced user some inspiration on the immense possibilities you have with QGIS ?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog post is about QGIS relations and how they are edited in the attribute form with widgets in general, as well as some plugins that override the relations editor widget to improve usability and solve specific use cases. The start is quite basic. If you are already a relation [&hellip;]<\/p>\n","protected":false},"author":37,"featured_media":13502,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[15,16,161],"tags":[125],"class_list":["post-13455","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-qgis","category-qgis-plugins","category-uncategorised","tag-qgis-org"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2022\/11\/feature.png?fit=641%2C463&ssl=1","jetpack-related-posts":[{"id":2127,"url":"https:\/\/www.opengis.ch\/de\/2016\/09\/19\/qgis2-compatibility-plugin\/","url_meta":{"origin":13455,"position":0},"title":"QGIS2 compatibility plugin","author":"Marco Bernasocchi","date":"19. September 2016","format":false,"excerpt":"Lately I've been spending time porting a bigger plugin from QGIS 2.8 to 3 while maintaining 2.8 compatibility. You can find it at https:\/\/github.com\/opengisch\/qgis2compat\/ and https:\/\/plugins.qgis.org\/plugins\/qgis2compat\/ One code to rule them all. My target was to have to edit the source code as little as possible to simulate a lazy\u2026","rel":"","context":"In &quot;PyQt&quot;","block_context":{"text":"PyQt","link":"https:\/\/www.opengis.ch\/de\/category\/programming\/python\/pyqt\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":154,"url":"https:\/\/www.opengis.ch\/de\/2010\/12\/06\/qgis-plugins-starter-plugin\/","url_meta":{"origin":13455,"position":1},"title":"Qgis plugins starter plugin","author":"Marco Bernasocchi","date":"6. Dezember 2010","format":false,"excerpt":"Today I published my first QGis Python plugin. It does allow to configure a list of available plugins actions to execute in one click. It is published in pyqgis contributed repository and the source is developed on My GitHub Cheers Marco","rel":"","context":"In &quot;GIS&quot;","block_context":{"text":"GIS","link":"https:\/\/www.opengis.ch\/de\/category\/gis\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":243,"url":"https:\/\/www.opengis.ch\/de\/2011\/07\/06\/globe-is-in-qgis-trunk\/","url_meta":{"origin":13455,"position":2},"title":"Globe is in QGIS Trunk","author":"Marco Bernasocchi","date":"6. Juli 2011","format":false,"excerpt":"Last night Pirmin committed our Globe plugin to the QGIS trunk. this means that getting the needed dependencies (see below), building QGIS with -DWITH_GLOBE=ON and activating the plugin its all it takes to get a super globe running on QGIS. Dependencies: sudo apt-get install osgearth osgearth-dev openscenegraph (should be enough)\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.opengis.ch\/de\/category\/programming\/cpp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":356,"url":"https:\/\/www.opengis.ch\/de\/2012\/02\/01\/qgis-gets-compass-support\/","url_meta":{"origin":13455,"position":3},"title":"QGIS gets Compass support","author":"Marco Bernasocchi","date":"1. Februar 2012","format":false,"excerpt":"After implementing GPS support for QGIS on Android I've implemented a plugin that reads the internal compass readings and shows the value in a small dock widget. All theese new features are available in the master-alpha4 version and the nightly. Hope you enjoy","rel":"","context":"In &quot;Android&quot;","block_context":{"text":"Android","link":"https:\/\/www.opengis.ch\/de\/category\/programming\/android\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2012\/02\/P20120201003618-300x187.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":10660,"url":"https:\/\/www.opengis.ch\/2020\/04\/16\/plugin-manager-improvement\/","url_meta":{"origin":13455,"position":4},"title":"Plugin Manager improvement","author":"Olivier","date":"16. April 2020","format":false,"excerpt":"During the 2020 Swiss QGIS Users Group annual meeting, a proposal to improve the plugin manager was accepted to improve QGIS' plugin manager. Starting with version 3.14, it will be possible to choose whether to install the stable or the experimental version of individual plugins. This feature will greatly improve\u2026","rel":"","context":"In &quot;QGIS&quot;","block_context":{"text":"QGIS","link":"https:\/\/www.opengis.ch\/de\/category\/gis\/qgis\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2020\/04\/qgis-plugin-manager-1.png?fit=952%2C519&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2020\/04\/qgis-plugin-manager-1.png?fit=952%2C519&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2020\/04\/qgis-plugin-manager-1.png?fit=952%2C519&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2020\/04\/qgis-plugin-manager-1.png?fit=952%2C519&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":14623,"url":"https:\/\/www.opengis.ch\/de\/2024\/06\/25\/swiss-locator-plugin-3-0-is-here-with-exciting-features\/","url_meta":{"origin":13455,"position":5},"title":"QGIS Swiss Locator 3.0 brings elevation profiles and vector tiles","author":"Germ\u00e1n Carrillo","date":"25. Juni 2024","format":false,"excerpt":"Swiss Locator 3.0 for #QGIS is here! Access high-precision elevation profiles from Swisstopo's swissALTI3D data and integrate vector tiles easily. \ud83c\udf0d\ud83d\uddfa\ufe0f #SwissGIS #Swisstopo #SwissLocator","rel":"","context":"In &quot;3D&quot;","block_context":{"text":"3D","link":"https:\/\/www.opengis.ch\/de\/category\/3d\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/swiss_locator_profile.jpg?fit=1200%2C871&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/swiss_locator_profile.jpg?fit=1200%2C871&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/swiss_locator_profile.jpg?fit=1200%2C871&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/swiss_locator_profile.jpg?fit=1200%2C871&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/swiss_locator_profile.jpg?fit=1200%2C871&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_shortlink":"https:\/\/wp.me\/pbdBtI-3v1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/posts\/13455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/comments?post=13455"}],"version-history":[{"count":22,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/posts\/13455\/revisions"}],"predecessor-version":[{"id":13506,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/posts\/13455\/revisions\/13506"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/media\/13502"}],"wp:attachment":[{"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/media?parent=13455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/categories?post=13455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.opengis.ch\/de\/wp-json\/wp\/v2\/tags?post=13455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}