Пример #1
0
func main() {

	test := "e`miGhmocNpD{TeLm|@[email protected]{[email protected]@nFeVsHas@}[email protected]}[email protected][e}@ke@_Q}f@}[email protected]}@[email protected]`BxRs_A~A{CweByOgnB{[email protected]@m~D}Xo`Ay`@mwBw\\atEbJat@`[email protected]{[email protected]@s`[email protected][email protected]}NKutBxt@[email protected]@qsIobA}}Ca\\kfFqa@}gGgnA_aKaoEmn\\ypAswJ{RonEkYgnD{|@cmGnZmiByTqxCmt@{[email protected][email protected]@czKsc@{`[email protected]}[email protected]@uiBmWsgAeZm[_`@qqAgZwyCc`@a{@[email protected]|@yL{[email protected]@[email protected]@[email protected]}BcDkhDcoAgpDydCwyG{aAqpD_tBssM_hBe`KscAsxEaiAwyHjB}cApWmfB{cAy`OutCo`[email protected]\\[email protected]{lAgOiyBgXahBmCkaCgUs}[email protected][email protected]@[email protected]`Pe{B{[email protected]@wmAo`@oaCo|@[email protected]|@[email protected]@uhBuXg|[email protected]@u_Oop@[email protected]@kjEs|A}[email protected]@c|D}j@{_EkcAioBg^}rA{[email protected]@[email protected]@woA_g@[email protected]|@uU{iBm|@ojBwvAomBunBkrBywBi`@ssA}MwsAlIylAeH{[email protected]@k`[email protected]@[email protected][email protected][email protected]_DkkDctFu|[email protected]@wWozA}[email protected]@[email protected]`@[email protected]}][email protected]_tAcgCuuC_pFsjByfEkfB{hEqtAi`FufDwoKe}D}[email protected]{[email protected]}gCutIgiAcyDusFe{RwwAguHt@{[email protected]@e`[email protected]@[email protected]{[email protected]_qEqTe{[email protected]@[email protected]@_`As}@whCkuDmyLqeAgiDqq@}jAelA{[email protected]_Ayx@_[ooAw`[email protected]@akFo_Ai{F_YqoAaBysAdL}qFwGipAhCm|EpHywClWcjAT{[email protected]@w{AgcB{_Egq@{[email protected]@w_Aiw@[email protected]"
	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)
}
Пример #2
0
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()
	}
}