Skip to main content
Question

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


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?

5 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • 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
  • March 21, 2018
takashi wrote:

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
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 22, 2018
takashi wrote:

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
  • March 23, 2018
takashi wrote:

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
  • March 23, 2018
smurf wrote:

 

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

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings