Skip to main content
Question

Geometry Template, problem getting list attributes when using variable for indices

  • March 21, 2018
  • 5 replies
  • 19 views

Forum|alt.badge.img

Hi, Im using an XML templates with a geometry template.

I have a for loop and I have my positions in a list attribute.

Whenever I use the variable for the indices fme:get-attribute("_Positions{$i}.y") I get no results but if I use the same value that is in $i it works, I don't understand why I'm getting no results.

Here's the GEOM template with some extra rows added for testing that value 0 exists.

for $i in (0 to (xs:integer({fme:get-attribute("_element_count")})-1))

 

return {

 

<LineCoordinate>

 

<Seq_No>{$i+1}</Seq_No>

 

<latitude_position>{fme:get-attribute("_Positions{$i}.y")}</latitude_position>

 

<longitude_position>{fme:get-attribute("_Positions{$i}.x")}</longitude_position>

 

<latitude_position>{fme:get-attribute("_Positions{0}.x")}</latitude_position>

 

<longitude_position>{fme:get-attribute("_Positions{0}.x")}</longitude_position>

 

</LineCoordinate>

}

Heres the results that prove the list attributes has a value to get

<LineCoordinate>

 

<Seq_No>1</Seq_No>

 

<latitude_position/>

 

<longitude_position/>

 

<latitude_position>-11912.295936030823</latitude_position>

 

<longitude_position>-11912.295936030823</longitude_position>

 

</LineCoordinate>

So when Seq_No is 1 then $i must be 0 so Im expecting the same results here from

fme:get-attribute("_Positions{$i}.y") and

fme:get-attribute("_Positions{0}.y")

Im not sure why the 1st returns no value but the second does.

Can anyone see what I'm missing?

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.

5 replies

takashi
Celebrity
  • 7843 replies
  • March 21, 2018

Hi @smurf, I think you will have to create attribute names by concatenating parts, like this.

<latitude_position>{fme:get-attribute("_Positions{"||$i||"}.y")}</latitude_position>
<longitude_position>{fme:get-attribute("_Positions{"||$i||"}.x")}</longitude_position>

In this case, this expression is also available. FYI

let $lngs := fme:get-list-attribute("_Positions{}.x")
for $lat at $i in fme:get-list-attribute("_Positions{}.y")
return
<LineCoordinate>
    <Seq_No>{$i}</Seq_No>
    <latitude_position>{$lat}</latitude_position>
    <longitude_position>{$lngs[$i]}</longitude_position>
</LineCoordinate>


Forum|alt.badge.img
  • Author
  • 26 replies
  • March 21, 2018

Hi @smurf, I think you will have to create attribute names by concatenating parts, like this.

<latitude_position>{fme:get-attribute("_Positions{"||$i||"}.y")}</latitude_position>
<longitude_position>{fme:get-attribute("_Positions{"||$i||"}.x")}</longitude_position>

In this case, this expression is also available. FYI

let $lngs := fme:get-list-attribute("_Positions{}.x")
for $lat at $i in fme:get-list-attribute("_Positions{}.y")
return
<LineCoordinate>
    <Seq_No>{$i}</Seq_No>
    <latitude_position>{$lat}</latitude_position>
    <longitude_position>{$lngs[$i]}</longitude_position>
</LineCoordinate>

 

aaah thanks, I see what I was doing wrong now, didnt realise the concat was needed there but makes sense, I'll try this tomorrow but probably use the second method as thats nice too.

 

 

I still think I'm doing it slightly wrong still as I should be querying the geom ideally in geom template but unsure how to get the return from the xquery get points into the XML format I want all within the editor.

 

 

 


takashi
Celebrity
  • 7843 replies
  • March 22, 2018

Hi @smurf, I think you will have to create attribute names by concatenating parts, like this.

<latitude_position>{fme:get-attribute("_Positions{"||$i||"}.y")}</latitude_position>
<longitude_position>{fme:get-attribute("_Positions{"||$i||"}.x")}</longitude_position>

In this case, this expression is also available. FYI

let $lngs := fme:get-list-attribute("_Positions{}.x")
for $lat at $i in fme:get-list-attribute("_Positions{}.y")
return
<LineCoordinate>
    <Seq_No>{$i}</Seq_No>
    <latitude_position>{$lat}</latitude_position>
    <longitude_position>{$lngs[$i]}</longitude_position>
</LineCoordinate>

If you want to extract coordinates directly from the input geometry with an XQeury expression and then arrange them into your desired XML schema, this example might help you. Assuming that the input feature has a Line geometry (not aggregate).

 

<Line>{
    let $points := fn:tokenize(geom:get-points('xy', ' ', '/'), '/')
    for $p at $i in $points
    let $c := fn:tokenize($p, ' ')
    return
    <LineCoordinate>
        <Seq_No>{$i}</Seq_No>
        <latitude_position>{$c[2]}</latitude_position>
        <longitude_position>{$c[1]}</longitude_position>
    </LineCoordinate>
}</Line>

Forum|alt.badge.img
  • Author
  • 26 replies
  • March 23, 2018

Hi @smurf, I think you will have to create attribute names by concatenating parts, like this.

<latitude_position>{fme:get-attribute("_Positions{"||$i||"}.y")}</latitude_position>
<longitude_position>{fme:get-attribute("_Positions{"||$i||"}.x")}</longitude_position>

In this case, this expression is also available. FYI

let $lngs := fme:get-list-attribute("_Positions{}.x")
for $lat at $i in fme:get-list-attribute("_Positions{}.y")
return
<LineCoordinate>
    <Seq_No>{$i}</Seq_No>
    <latitude_position>{$lat}</latitude_position>
    <longitude_position>{$lngs[$i]}</longitude_position>
</LineCoordinate>

 

thanks you've been a great help as always,

 

one more thing, can I apply rounding in here, I know there the FME @Round function but it seems to only round to an integer, I want to round my positions to 6 decimal places, Im unsure what language is being used in this editor is it python?

 

Im not sure what to google to find the syntax to try stuff out

Forum|alt.badge.img
  • Author
  • 26 replies
  • March 23, 2018

 

thanks you've been a great help as always,

 

one more thing, can I apply rounding in here, I know there the FME @Round function but it seems to only round to an integer, I want to round my positions to 6 decimal places, Im unsure what language is being used in this editor is it python?

 

Im not sure what to google to find the syntax to try stuff out
nevermind, tried using round() inside the curly braces and it worked, I assume its python in here