Skip to main content
Solved

XML templater conditions based on geometry

  • February 7, 2020
  • 3 replies
  • 26 views

Forum|alt.badge.img

I want to export some data to gml, and I see that I have some complex geometries, which results in different sets of coordinates for each polygon (after geometry extractor). I made a list and each element within the list contains the set of coordinates for each segment of the geometry, but not all the polygons have the extra dimensions.

Therefore, I want to make an if-statement where only the extra xml-statement is shown when there is data in the list. I tried using this, but it does not work.

Can anybody point out an error in the statement.

Not only the line with the statement posList..., but also the other statements around them, I want to delete when the list element is not existing.

 

 

If there is another way of doing this (e.g. with a loop), I am open to suggestions.

 

</gml:exterior>

 

If {(fme:has-attribute("interior_xy_l{0}.part")) then (

 

<gml:exterior>

 

<gml:LinearRing>

 

<gml:posList>{fme:get-attribute("interior_xy_l{0}.part")}</gml:posList>

 

</gml:LinearRing>

 

</gml:exterior>)

 

else ()}

 

 

Best answer by takashi

Hi @evagadeyne, this is just a partial and syntactic correction on the if statement. I don't know if it's correct in the context of the entire expression.

{
    if (fme:has-attribute("interior_xy_l{0}.part"))
    then
    <gml:exterior>
        <gml:LinearRing>
            <gml:posList>{fme:get-attribute("interior_xy_l{0}.part")}</gml:posList>
        </gml:LinearRing>
    </gml:exterior>
    else ()
}
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

takashi
Celebrity
  • Best Answer
  • February 7, 2020

Hi @evagadeyne, this is just a partial and syntactic correction on the if statement. I don't know if it's correct in the context of the entire expression.

{
    if (fme:has-attribute("interior_xy_l{0}.part"))
    then
    <gml:exterior>
        <gml:LinearRing>
            <gml:posList>{fme:get-attribute("interior_xy_l{0}.part")}</gml:posList>
        </gml:LinearRing>
    </gml:exterior>
    else ()
}

Forum|alt.badge.img
  • Author
  • February 7, 2020

Thank you @takashi

this works! Can I make a loop over all the list members from 0 to 5 above the if statement, so I do not need to copy-paste this 6 times?


takashi
Celebrity
  • February 7, 2020

Thank you @takashi

this works! Can I make a loop over all the list members from 0 to 5 above the if statement, so I do not need to copy-paste this 6 times?

Yes, you can do that with a for statement. This expression iterates to create <exterior> element for every element in the list.

{
    for $p in fme:get-list-attribute("interior_xy_l{}.part")
    return
    <gml:exterior>
        <gml:LinearRing>
            <gml:posList>{$p}</gml:posList>
        </gml:LinearRing>
    </gml:exterior>
}

 

If you need to limit the maximum number of iteration to 6, for example, this expression is available. Note: $i will store a number starting with 1.

{
    for $p at $i in fme:get-list-attribute("interior_xy_l{}.part")
    where $i < 7
    return
    <gml:exterior>
        <gml:LinearRing>
            <gml:posList>{$p}</gml:posList>
        </gml:LinearRing>
    </gml:exterior>
}