123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package util
- import (
- "fmt"
- "github.com/beevik/etree"
- )
- // GetStartAndEnd
- // - filepath 文件路径 "D:\\test.xosc"
- func GetStartAndEnd(filepath string) (string, string, string, string) {
- startPositionX := ""
- startPositionY := ""
- endPositionX := ""
- endPositionY := ""
- doc := etree.NewDocument()
- if err := doc.ReadFromFile(filepath); err != nil {
- panic(err)
- }
- storys := doc.SelectElement("OpenSCENARIO").SelectElement("Storyboard").SelectElements("Story")
- for _, story := range storys {
- for _, attr := range story.Attr {
- if attr.Key == "name" && attr.Value == "mystory_ego" {
- events := story.SelectElement("Act").SelectElement("ManeuverGroup").SelectElement("Maneuver").SelectElements("Event")
- for _, event := range events {
- for _, attr2 := range event.Attr {
- if attr2.Key == "name" && attr2.Value == "Event1" {
- vertexs := event.SelectElement("Action").SelectElement("PrivateAction").SelectElement("RoutingAction").SelectElement("FollowTrajectoryAction").SelectElement("Trajectory").SelectElement("Shape").SelectElement("Polyline").SelectElements("Vertex")
- for i, vertex := range vertexs {
- if i == 0 {
- worldPosition := vertex.SelectElement("Position").SelectElement("WorldPosition")
- for _, attr3 := range worldPosition.Attr {
- if attr3.Key == "x" {
- startPositionX = attr3.Value
- }
- if attr3.Key == "y" {
- startPositionY = attr3.Value
- }
- }
- }
- if i == len(vertexs)-1 {
- worldPosition := vertex.SelectElement("Position").SelectElement("WorldPosition")
- for _, attr3 := range worldPosition.Attr {
- if attr3.Key == "x" {
- endPositionX = attr3.Value
- }
- if attr3.Key == "y" {
- endPositionY = attr3.Value
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- fmt.Println(startPositionX)
- fmt.Println(startPositionY)
- fmt.Println(endPositionX)
- fmt.Println(endPositionY)
- return startPositionX, startPositionY, endPositionX, endPositionY
- }
|