Hello,
How would you create a sequence of Landmarks from those two classes:
case class Landmark(id: String, point: Point[_3D])
case class Landmarks(values: Seq[Landmark[_3D]])
val idLM0 = seqLMs(0).attribute(“key”).get.toString() // get the first ID
val Pt0: Point[_3D] = Point(seqLMs(0).text.split(" “)(0).toDouble, seqLMs(0).text.split(” “)(1).toDouble, seqLMs(0).text.split(” ")(2).toDouble)
val LM0 = Landmark(idLM0, Pt0)
for (i <- 1 to seqLMs.length-1){
val idLM01 = seqLMs(i).attribute("key").get.toString() // get the first ID
val Pt: Point[_3D] = Point(seqLMs(i).text.split(" ")(0).toDouble, seqLMs(i).text.split(" ")(1).toDouble,
seqLMs(i).text.split(" ")(2).toDouble)
val LM = Landmark(idLM01, Pt) // use zip to create the LM
LMsSeq =+ Seq(LM) // ERROR HERE
}
}
I tried to create an initial Point (called LM0 here) and then I tried to iterate but I got an error when trying to append.
Assuming you meant += instead of =+, I see a couple of problems here:
LMsSeq += Seq(LM) // ERROR HERE
You’re trying to change an immutable collection. If you want
mutability (odds are you don’t, but you might), look into scala.collection.mutable.Buffer:
You’ve said that LMsSeq is a Seq[Landmark[_3D]], but you’re
trying to add a Seq[Landmark[_3D]] (presumably, I’m guessing about
what LM is). If you have a Buffer, you can add single thigs, like
the above, or you can add a bunch with ++=: