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n@ed@kuAcpDuxAi_Dmn@szCcnFwoNkpDevEmn@_`As}@whCkuDmyLqeAgiDqq@}jAelA{gBkcAmwBmVkkDam@mwBs_Ayx@_[ooAw`A_wDqf@ebDel@akFo_Ai{F_YqoAaBysAdL}qFwGipAhCm|EpHywClWcjAT{n@cn@w{AgcB{_Egq@{j@sYkMai@w_Aiw@_uAwIoO_PkIkF~MmHn@gCiD" points, err := polyline.Decode(test, 2) if err != nil { return } kml := gokml.NewKML("teste") //style := gokml.NewStyle("linestringStyle", 127, 255, 255, 0) linestring := gokml.NewLineString() placemark := gokml.NewPlacemark("Rota", "route between two points", linestring) //placemark.SetStyle("linestringStyle") kml.AddFeature(placemark) //kml.AddFeature(style) for i := 0; i < len(points); i = i + 2 { point := gokml.NewPoint(points[i], points[i+1], 0) linestring.AddPoint(point) } kmlString := kml.Render() err = ioutil.WriteFile("teste.kml", []byte(kmlString), 0644) check(err) fmt.Printf("%+v\n", kmlString) }
func main() { if len(os.Args) < 2 { log.Fatal("Usage: route-kml MBTA_GTFS.zip") } feed := gtfsparser.NewFeed() if err := feed.Parse(os.Args[1]); err != nil { log.Fatal(err) } routeMap := map[string][]*gtfs.Shape{} for _, trip := range feed.Trips { if trip.Shape == nil { continue } found := false for _, shape := range routeMap[trip.Route.Id] { if shape == trip.Shape { found = true break } } if !found { routeMap[trip.Route.Id] = append(routeMap[trip.Route.Id], trip.Shape) } } for routeID, shapes := range routeMap { fmt.Printf("Generating for route %s\n", routeID) sort.Sort(ByShapeID(shapes)) f, err := os.Create(routeID + ".kml") if err != nil { log.Fatal(err) } kml := gokml.NewKML(routeID) for _, shape := range shapes { ls := gokml.NewLineString() for _, p := range shape.Points { point := gokml.NewPoint(float64(p.Lat), float64(p.Lon), 0) ls.AddPoint(point) } pm := gokml.NewPlacemark(shape.Id, shape.Id, ls) kml.AddFeature(pm) } io.WriteString(f, kml.Render()) f.Close() } }