Skip to main content

I have a xml file which has the following structure:

<Alignement ObjectId="9a8ed34d-2da9-4f37-9d5c-6569f665ce4f" Naam="R-HAVEN
SP.701" Status="onbekend" RevisieNummer="0" GroepId="b885abb4-e34d-40d0-a752-362869bf8667" Lengte="2134.04431" Start="0" Type="Alignement" IsSubcomponentenDoorgerekend="true">

<CombiPuntenHorVer>

<SpoorasInfoPunt ObjectId="0c131e39-de81-4244-905f-e7f27057566d" GroepId="7e1bd81b-0ce3-4144-947b-b095b5020b53" offset="0" Spoorzijde="Links" Bulgefactor="0" z_verkanting="0" dY_verkanting="0" factor="0" hoek_XY="0" hoek_YZ="0" Min_R_Horizontaal="0" Metrering="0">


<Geometrie>

<CoordinaatSysteem>

<Locatie KeuzeCSType="Rijksdriehoek" X="145146.355" Y="345251.230" Z="3.5"/>
</CoordinaatSysteem>

</Geometrie>

</SpoorasInfoPunt>

<SpoorasInfoPunt ObjectId="9021e8e2-4599-45c6-9b16-9f3418545aab" GroepId="7e1bd81b-0ce3-4144-947b-b095b5020b53" offset="0" Spoorzijde="Links" Bulgefactor="0" z_verkanting="0" dY_verkanting="0" factor="0" hoek_XY="0" hoek_YZ="0" Min_R_Horizontaal="0" Metrering="16.795950366832663">


<Geometrie>

<CoordinaatSysteem>

<Locatie KeuzeCSType="Rijksdriehoek" X="145146.455" Y="345251.330" Z="3.4"/>
</CoordinaatSysteem>

 


</Geometrie>

</SpoorasInfoPunt>

.......

</CombiPuntenHorVer>

</Alignement>


Within the CombiPuntenHorVer element there can be numerous SpoorasInfoPunt elements
I'm trying to make a xfMap file which translates this structure into one polyline.
So when I have lets say 50 SpoorasInfoPunt elements in a CombiPuntHorVer element in a Alignement element it will create an Alignement record with all the attributes from the Alignement and a polyline shape which has 50 vertices (each vertice is a SpoorasInfoPunt).
can somebody give me a clou how to do this.
here is the xfmap file I created but it doesn't work:
<?xml version="1.0" encoding="UTF-8"?>

 


<!DOCTYPE xfMap SYSTEM "xfMap.dtd">
<xfMap type="Spoorlayout">
<schema-type>
<scan scan-empty-attributes="true"/>
</schema-type>
<!-- Spoorlayout -->
<feature-map>
<mapping match="Alignement">
<apply-attribute-sets>
<attribute-set>
<attributes>
<attribute>
<name><literal expr="Alignement_Id"/></name>
<value><extract expr="@ObjectId"/> </value>
</attribute>
<attribute>
<name><literal expr="Naam"/></name>
<value><extract expr="@Naam"/></value>
</attribute>
<attribute>
<name><literal expr="Status"/></name>
<value><extract expr="@Status"/></value>
</attribute>
<attribute>
<name><literal expr="RevisieNummer"/></name>
<value><extract expr="@RevisieNummer"/></value>
</attribute>
<attribute>
<name><literal expr="GroepId"/></name>
<value><extract expr="@GroepId"/></value>
</attribute>
<attribute>
<name><literal expr="Lengte"/></name>
<value><extract expr="@Lengte"/></value>
</attribute>
<attribute>
<name><literal expr="Start"/></name>
<value><extract expr="@Start"/></value>
</attribute>
<attribute>
<name><literal expr="Type"/></name>
<value><extract expr="@Type"/></value>
</attribute>
<attribute>
<name><literal expr="IsSubcomponentenDoorgerekend"/></name>
<value><extract expr="@IsSubcomponentenDoorgerekend"/></value>
</attribute>
</attributes>
</attribute-set>
</apply-attribute-sets>
<geometry activate="xml-line"></geometry>
</mapping>
</feature-map>
<feature-content-map>
<mapping match="SpoorasInfoPunt">
<geometry>
<data name="x">
<extract expr="./Geometrie/CoordinaatSysteem/Locatiei@X]"/>
</data>
<data name="y">
<extract expr="./Geometrie/CoordinaatSysteem/Locatiei@Y]"/>
</data>
<data name="z">
<extract expr="./Geometrie/CoordinaatSysteem/Locatiei@Z]"/>
</data>
</geometry>
</mapping>
</feature-content-map>
</xfMap>

Hi @bertdoeve cant really help you with the xfMap, but would like to suggest using the XML reader in 2016 since it can map all the attributes for you with a few clicks.

After that is a matter of recreating the gml geometry with the GeometryReplacer.

Veel succes!


Hi @bertdoeve,

Could you try this xfmap?

<xfMap>

   <note> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </note>      
   <feature-map>
      <note> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </note>
      <note> map Alignement into feature </note>
      <mapping match="Alignement">
         <feature-type>
            <matched expr="local-name"/>
         </feature-type>
         <note> Not sure how many CombiPuntenHorVer an Alignement may have, so just in case start an aggregate to hold multiple lines </note>
         <geometry activate="xml-aggregate">
            <data name="keep-as-aggregate">
               <literal expr="false"/>
            </data>
         </geometry>      
         <note> automatically map some attributes with the structure construct, ignore CombiPuntenHorVer and its children </note>
         <structure map-empty-elements="yes" matched-prefix="no" matched-attributes="yes" except="CombiPuntenHorVer"/>
      </mapping>
   </feature-map>

   <note> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </note>      
   <feature-content-map>
      <note> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </note>      
      <note> create a new line for each CombiPuntenHorVer </note>
      <mapping match="CombiPuntenHorVer">
         <note> let the line sit on the stack to receive point geometries from SpoorasInfoPunt </note>
         <geometry activate="xml-line"/>                          
      </mapping>

      <note> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ </note>      
      <note> create a point geometry for each Locatie (We are not directly mapping SpoorasInfoPunt, but digging into the Locatie instead) </note>
      <mapping match="SpoorasInfoPunt/Geometrie/CoordinaatSysteem/Locatie">
         <geometry activate="xml-point">    
            <data name="axis-separator">
               <literal expr="whitespace"/>
            </data>
            <data name="coord-separator">
               <literal expr="whitespace"/>
            </data>
            <data name="axis-order">
               <literal expr="1,2,3"/>
            </data>            
            <data name="data-string">
               <extract expr="@X"/>
               <literal expr=" "/>
               <extract expr="@Y"/>
               <literal expr=" "/>
               <extract expr="@Z"/>
            </data>                          
         </geometry>
      </mapping>
   </feature-content-map>
   
</xfMap>

hi @juanchuchow1323

Thank you for your answer. Unfortunatly your answer results in another problem.

it is possible that in the xml alignement elements exist with only one SpoorasInfoPunt element.

so the constructor cann't construct a line because there is only one point. Is there a way to exclude those alignement elements?

now the readers reports an error and stops translating.


Hi @bertdoeve,

You could set the XML reader "Continue on Geometry Error" parameter to "Yes", and/or, modify the <geometry activate="xml-line"/> from the xfmap above to:

<geometry activate="xml-line">
  <data name="allow-incomplete-geometry">
    <literal expr="true"/>
  </data>
</geometry>

Either "allow-incomplete-geometry" or "demote-incomplete-geometry" may be used, the difference is explained here:

http://docs.safe.com/fme/2017.0/html/FME_Desktop_Documentation/FME_ReadersWriters/xml/xml_line.htm?Highlight=xml-line


Reply