Open signedav opened 2 years ago
When I would do the hacky way updating my existing data, the attribute description of my extendeded building would be overwritten with NULL.
Well the simple response to "why I cannot import the data from the base model to the extended model" is, that the extended model can have 1. more restrictive constraints and 2. additional attributes that have constraints. So the data of the base model would be invalid or cannot even be imported, because of database constraints.
While an extended model contains the base model, the export into the base model format is something that can be properly achieved. The other way is a real transformation of two different models - it's just that the format is mostly very similar. But this is the reason why it most possibly won't be a default integration in ili2db.
The approach with XSL we know from the successful project MGDM2OEREB: https://github.com/openoereb/mgdm2oereb XSLT is a way of transform XML structured files. It's solid and well integrated in all the popular programming languages.
INTERLIS 2.3;
/* Ortsplanung as national model */
MODEL Ortsplanung_V1_1 (en) AT "https://modelbaker.ch" VERSION "2023-03-29" =
IMPORTS LocalisationCH_V1,GeometryCHLV95_V1;
DOMAIN
CHSurface = SURFACE WITH (STRAIGHTS) VERTEX GeometryCHLV95_V1.Coord2 WITHOUT OVERLAPS > 0.001;
TOPIC Konstruktionen =
CLASS Gebaeude =
Name : MANDATORY TEXT*99;
Geometrie : MANDATORY Ortsplanung_V1_1.CHSurface;
END Gebaeude;
CLASS BesitzerIn =
Vorname : MANDATORY TEXT*99;
Nachname : MANDATORY TEXT*99;
END BesitzerIn;
ASSOCIATION Gebaeude_BesitzerIn =
BesitzerIn -- {0..1} BesitzerIn;
Gebaeude -- {0..*} Gebaeude;
END Gebaeude_BesitzerIn;
END Konstruktionen;
END Ortsplanung_V1_1.
<?xml version="1.0" encoding="UTF-8"?><TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<HEADERSECTION SENDER="ili2pg-4.10.0-c2af4b50c5475f788286f974812b52bb0f9b19bc" VERSION="2.3">
<MODELS>
<MODEL NAME="Ortsplanung_V1_1" VERSION="2023-03-29" URI="https://modelbaker.ch"></MODEL>
<MODEL NAME="AnotherModel_V1_2" VERSION="2021-04-05" URI="https://modelbaker.ch"></MODEL>
</MODELS>
</HEADERSECTION>
<DATASECTION>
<Ortsplanung_V1_1.Konstruktionen BID="bff5ec3c-4851-4de4-9527-75115aa4ea89">
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="8803af6d-ac97-48a9-9bfe-99ea543b8f80"><Vorname>Uma</Vorname><Nachname>Thurman</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="1011e8e4-bfc5-4e40-b732-3ac38c0e2be6"><Vorname>Bill</Vorname><Nachname>Murray</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Ortsplanung_V1_1.Konstruktionen.Gebaeude TID="5cdad41d-2bd6-45a8-a0cb-904ff5a8a611"><Name>Kino Rex</Name><Geometrie><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699839.636</C1><C2>1262336.345</C2></COORD><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD><COORD><C1>2699822.808</C1><C2>1262352.067</C2></COORD><COORD><C1>2699828.189</C1><C2>1262333.300</C2></COORD><COORD><C1>2699839.636</C1><C2>1262336.345</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn REF="1011e8e4-bfc5-4e40-b732-3ac38c0e2be6"></BesitzerIn></Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Ortsplanung_V1_1.Konstruktionen.Gebaeude TID="f0cd1933-ed97-409c-b8e8-7249f4b76fe1"><Name>Bills Eckkneipe</Name><Geometrie><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD><COORD><C1>2699831.336</C1><C2>1262370.085</C2></COORD><COORD><C1>2699819.095</C1><C2>1262366.784</C2></COORD><COORD><C1>2699822.808</C1><C2>1262352.067</C2></COORD><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn REF="1011e8e4-bfc5-4e40-b732-3ac38c0e2be6"></BesitzerIn></Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Ortsplanung_V1_1.Konstruktionen.Gebaeude TID="eb3e8054-ccf5-4067-8dc6-7875b2316e0f"><Name>Mini Alien Pub</Name><Geometrie><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699845.503</C1><C2>1262357.843</C2></COORD><COORD><C1>2699852.475</C1><C2>1262360.010</C2></COORD><COORD><C1>2699852.509</C1><C2>1262364.205</C2></COORD><COORD><C1>2699847.351</C1><C2>1262365.271</C2></COORD><COORD><C1>2699843.672</C1><C2>1262363.036</C2></COORD><COORD><C1>2699843.122</C1><C2>1262359.425</C2></COORD><COORD><C1>2699845.503</C1><C2>1262357.843</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn REF="8803af6d-ac97-48a9-9bfe-99ea543b8f80"></BesitzerIn></Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="414dc948-1f37-4000-ad36-43e604755ae6"><Vorname>Moritz</Vorname><Nachname>Bleibtreu</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="7fb847fd-9af9-495c-a900-9eb4998af9a8"><Vorname>Tom</Vorname><Nachname>Hanks</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Ortsplanung_V1_1.Konstruktionen.Gebaeude TID="4560b33e-c880-4eb5-91ce-8ab4231340d1"><Name>Bubba Gump Halle</Name><Geometrie><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699847.874</C1><C2>1262313.436</C2></COORD><COORD><C1>2699841.505</C1><C2>1262336.842</C2></COORD><COORD><C1>2699826.539</C1><C2>1262332.861</C2></COORD><COORD><C1>2699832.589</C1><C2>1262307.226</C2></COORD><COORD><C1>2699846.282</C1><C2>1262310.411</C2></COORD><COORD><C1>2699845.486</C1><C2>1262312.640</C2></COORD><COORD><C1>2699847.874</C1><C2>1262313.436</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn REF="7fb847fd-9af9-495c-a900-9eb4998af9a8"></BesitzerIn></Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Ortsplanung_V1_1.Konstruktionen.Gebaeude TID="5742c809-73da-4445-bc0f-d5a5d5c5f539"><Name>Alte Metzg</Name><Geometrie><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD><COORD><C1>2699845.503</C1><C2>1262357.843</C2></COORD><COORD><C1>2699843.122</C1><C2>1262359.425</C2></COORD><COORD><C1>2699843.672</C1><C2>1262363.036</C2></COORD><COORD><C1>2699847.351</C1><C2>1262365.271</C2></COORD><COORD><C1>2699852.509</C1><C2>1262364.205</C2></COORD><COORD><C1>2699852.475</C1><C2>1262360.010</C2></COORD><COORD><C1>2699868.980</C1><C2>1262363.861</C2></COORD><COORD><C1>2699865.266</C1><C2>1262379.541</C2></COORD><COORD><C1>2699831.336</C1><C2>1262370.085</C2></COORD><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn REF="414dc948-1f37-4000-ad36-43e604755ae6"></BesitzerIn></Ortsplanung_V1_1.Konstruktionen.Gebaeude>
</Ortsplanung_V1_1.Konstruktionen>
</DATASECTION>
</TRANSFER>
INTERLIS 2.3;
/* Extended Ortsplanung as cantonal model importing national model */
MODEL Kantonale_Ortsplanung_V1_1 (en) AT "https://modelbaker.ch" VERSION "2023-03-29" =
IMPORTS Ortsplanung_V1_1;
TOPIC Konstruktionen EXTENDS Ortsplanung_V1_1.Konstruktionen =
CLASS Gebaeude (EXTENDED)=
Beschreibung: TEXT;
Referenzcode: TEXT;
!!@ ilivalid.msg = "Beschreibung and/or Referenzcode must be defined."
SET CONSTRAINT DEFINED (Beschreibung) OR DEFINED (Referenzcode);
END Gebaeude;
END Konstruktionen;
END Kantonale_Ortsplanung_V1_1.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ili="http://www.interlis.ch/INTERLIS2.3"
version="1.0">
<!-- generic template for all nodes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- base model needs to be renamed -->
<xsl:template match="ili:MODEL">
<xsl:choose>
<xsl:when test="@NAME='Ortsplanung_V1_1'">
<MODEL NAME="Kantonale_Ortsplanung_V1_1" VERSION="{@VERSION}" URI="{@URI}"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ili:Ortsplanung_V1_1.Konstruktionen.Gebaeude">
<Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<xsl:apply-templates select="@*|node()"/>
<!-- default value to fulfill constraint -->
<Referenzcode>xxxx-000</Referenzcode>
</Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<HEADERSECTION SENDER="ili2pg-4.10.0-c2af4b50c5475f788286f974812b52bb0f9b19bc" VERSION="2.3">
<MODELS>
<MODEL xmlns="" NAME="Kantonale_Ortsplanung_V1_1" VERSION="2023-03-29" URI="https://modelbaker.ch"/>
</MODELS>
</HEADERSECTION>
<DATASECTION>
<Ortsplanung_V1_1.Konstruktionen BID="bff5ec3c-4851-4de4-9527-75115aa4ea89">
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="8803af6d-ac97-48a9-9bfe-99ea543b8f80"><Vorname>Uma</Vorname><Nachname>Thurman</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="1011e8e4-bfc5-4e40-b732-3ac38c0e2be6"><Vorname>Bill</Vorname><Nachname>Murray</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude xmlns="" xmlns:ili="http://www.interlis.ch/INTERLIS2.3" TID="5cdad41d-2bd6-45a8-a0cb-904ff5a8a611"><Name xmlns="http://www.interlis.ch/INTERLIS2.3">Kino Rex</Name><Geometrie xmlns="http://www.interlis.ch/INTERLIS2.3"><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699839.636</C1><C2>1262336.345</C2></COORD><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD><COORD><C1>2699822.808</C1><C2>1262352.067</C2></COORD><COORD><C1>2699828.189</C1><C2>1262333.300</C2></COORD><COORD><C1>2699839.636</C1><C2>1262336.345</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn xmlns="http://www.interlis.ch/INTERLIS2.3" REF="1011e8e4-bfc5-4e40-b732-3ac38c0e2be6"/><Referenzcode>xxxx-000</Referenzcode></Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude xmlns="" xmlns:ili="http://www.interlis.ch/INTERLIS2.3" TID="f0cd1933-ed97-409c-b8e8-7249f4b76fe1"><Name xmlns="http://www.interlis.ch/INTERLIS2.3">Bills Eckkneipe</Name><Geometrie xmlns="http://www.interlis.ch/INTERLIS2.3"><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD><COORD><C1>2699831.336</C1><C2>1262370.085</C2></COORD><COORD><C1>2699819.095</C1><C2>1262366.784</C2></COORD><COORD><C1>2699822.808</C1><C2>1262352.067</C2></COORD><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn xmlns="http://www.interlis.ch/INTERLIS2.3" REF="1011e8e4-bfc5-4e40-b732-3ac38c0e2be6"/><Referenzcode>xxxx-000</Referenzcode></Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude xmlns="" xmlns:ili="http://www.interlis.ch/INTERLIS2.3" TID="eb3e8054-ccf5-4067-8dc6-7875b2316e0f"><Name xmlns="http://www.interlis.ch/INTERLIS2.3">Mini Alien Pub</Name><Geometrie xmlns="http://www.interlis.ch/INTERLIS2.3"><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699845.503</C1><C2>1262357.843</C2></COORD><COORD><C1>2699852.475</C1><C2>1262360.010</C2></COORD><COORD><C1>2699852.509</C1><C2>1262364.205</C2></COORD><COORD><C1>2699847.351</C1><C2>1262365.271</C2></COORD><COORD><C1>2699843.672</C1><C2>1262363.036</C2></COORD><COORD><C1>2699843.122</C1><C2>1262359.425</C2></COORD><COORD><C1>2699845.503</C1><C2>1262357.843</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn xmlns="http://www.interlis.ch/INTERLIS2.3" REF="8803af6d-ac97-48a9-9bfe-99ea543b8f80"/><Referenzcode>xxxx-000</Referenzcode></Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="414dc948-1f37-4000-ad36-43e604755ae6"><Vorname>Moritz</Vorname><Nachname>Bleibtreu</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Ortsplanung_V1_1.Konstruktionen.BesitzerIn TID="7fb847fd-9af9-495c-a900-9eb4998af9a8"><Vorname>Tom</Vorname><Nachname>Hanks</Nachname></Ortsplanung_V1_1.Konstruktionen.BesitzerIn>
<Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude xmlns="" xmlns:ili="http://www.interlis.ch/INTERLIS2.3" TID="4560b33e-c880-4eb5-91ce-8ab4231340d1"><Name xmlns="http://www.interlis.ch/INTERLIS2.3">Bubba Gump Halle</Name><Geometrie xmlns="http://www.interlis.ch/INTERLIS2.3"><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699847.874</C1><C2>1262313.436</C2></COORD><COORD><C1>2699841.505</C1><C2>1262336.842</C2></COORD><COORD><C1>2699826.539</C1><C2>1262332.861</C2></COORD><COORD><C1>2699832.589</C1><C2>1262307.226</C2></COORD><COORD><C1>2699846.282</C1><C2>1262310.411</C2></COORD><COORD><C1>2699845.486</C1><C2>1262312.640</C2></COORD><COORD><C1>2699847.874</C1><C2>1262313.436</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn xmlns="http://www.interlis.ch/INTERLIS2.3" REF="7fb847fd-9af9-495c-a900-9eb4998af9a8"/><Referenzcode>xxxx-000</Referenzcode></Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
<Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude xmlns="" xmlns:ili="http://www.interlis.ch/INTERLIS2.3" TID="5742c809-73da-4445-bc0f-d5a5d5c5f539"><Name xmlns="http://www.interlis.ch/INTERLIS2.3">Alte Metzg</Name><Geometrie xmlns="http://www.interlis.ch/INTERLIS2.3"><SURFACE><BOUNDARY><POLYLINE><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD><COORD><C1>2699845.503</C1><C2>1262357.843</C2></COORD><COORD><C1>2699843.122</C1><C2>1262359.425</C2></COORD><COORD><C1>2699843.672</C1><C2>1262363.036</C2></COORD><COORD><C1>2699847.351</C1><C2>1262365.271</C2></COORD><COORD><C1>2699852.509</C1><C2>1262364.205</C2></COORD><COORD><C1>2699852.475</C1><C2>1262360.010</C2></COORD><COORD><C1>2699868.980</C1><C2>1262363.861</C2></COORD><COORD><C1>2699865.266</C1><C2>1262379.541</C2></COORD><COORD><C1>2699831.336</C1><C2>1262370.085</C2></COORD><COORD><C1>2699835.325</C1><C2>1262355.230</C2></COORD></POLYLINE></BOUNDARY></SURFACE></Geometrie><BesitzerIn xmlns="http://www.interlis.ch/INTERLIS2.3" REF="414dc948-1f37-4000-ad36-43e604755ae6"/><Referenzcode>xxxx-000</Referenzcode></Kantonale_Ortsplanung_V1_1.Konstruktionen.Gebaeude>
</Ortsplanung_V1_1.Konstruktionen>
</DATASECTION>
</TRANSFER>
And this can be imported properly with ili2db...
These are not limitations of this approach but limitations of a base-data2extended-data transformation in general:
Being able to choose a trafo file from the local system at the same moment like we choose the data file. (Sketch link: https://excalidraw.com/#json=0uLIHVrP_adBNmcBArGdv,ZR3KK6cB4WKQyWnhwvZGOg)
An integration into ilidata / UsabILIty Hub would be an interesting approach as well.
But this requires a redesign of the Wizard workflow. Some ideas already noted here https://gist.github.com/signedav/7c9e2c8e895003bd1f7a9b4dd80797c0#redesign-idea
Reanimation of this issue (on 03-2023)
Reopened this issue because it's a valid problem / use case for some users.
Exporting from extended model instance and importing into base model instance
Well possible. Just collect the data in the extended model instance, export the data with
--exportModels basemodelname
like #665 (exports data in the format of base model) and import it into your base model instance. See "I can create lower-authority-data and provide them to the top-authority" below...Exporting from base model instance and importing into extended model instance
Not possible. No function provides us to export data in the format of an extended model. The base model instance does not know about the extended model anyway.
So the questions is: Why I cannot import the data from the base model to the extended model?
Well, because an extended model has:
But in my case it would work
In lot's of cases the mentioned issues won't encounter because the extended models do not have more restrictive constraint or mandatory additional attributes. There the "hacky" way would work. See "Conclusions - Another hacky approach..." or the XSL Approach here https://github.com/opengisch/QgisModelBaker/issues/723#issuecomment-1491542164
Background (from 09-2022)
Topic
Not really a Model Baker issue, but needs to be discussed to be able to solve issues like https://github.com/opengisch/QgisModelBaker/issues/665 and https://github.com/opengisch/QgisModelBaker/issues/461
It's about the question how I do work on data coming from a base model on my extended model.
Test model:
Base Model
Extended Model
Problem
When I get data from the top authority, I would like to work on this data in my extended model form. But they are imported into the table based on the base model.
Cannot work on top-authority-data in the extended model way
So I cannot add any description to the data I got from the top authority. Is this normal?
I can create lower-authority-data and provide them to the top-authority
(I think this is the use case of most people)
--exportModels Bund_City_V1_1
to kantonbund_export.xtfConclusion:
Exporting from top model to minor model - adding stuff on minor model and export back to top model, seems to work fine and as expected. But working in the minor model on data of the top model, seems to limit them on the top level structure.
I would expect, that I can use the data from the base model in the way of the extended model. Like: How can I achieve, that I can set a description for the entry "Bundeshaus"?
A tried approach would be to import KantonOne_City_V1_1 in bund.gpkg and export the data with
--exportModels KantonOne_City_V1_1
to bundkanton_export.xtf:But of course - because the data has been collected in the table buildings of Bund_City_V1_1 - the buildings are all in this table in kantonone.gpkg as well.
Another hacky approach is to export it as Bund data and replace for all the extended objects (like building) the "Bund_City_V1_1" with "KantonOne_City_V1_1":
Working good. But is hacky.