예제 #1
0
// PathToGeoJSON ..
func (t Tracker) PathToGeoJSON(path []geo.Point) (string, error) {
	fc := new(gj.FeatureCollection)
	// Start marker
	var p *gj.Feature
	start := new(gj.Point)
	start.Type = `Point`
	c := new(gj.Coordinate)
	c[0] = gj.Coord(path[0].Lng)
	c[1] = gj.Coord(path[0].Lat)
	start.Coordinates = *c

	// Path line
	var f *gj.Feature
	line := new(gj.LineString)
	line.Type = `LineString`
	//var cordinates gj.Coordinates

	for _, p := range path {
		coord := new(gj.Coordinate)
		coord[0] = gj.Coord(p.Lng)
		coord[1] = gj.Coord(p.Lat)
		line.AddCoordinates(*coord)
		//cordinates = append(cordinates, *coord)
	}
	//line.AddCoordinates(cordinates)

	fmt.Println(line.Type)
	f = gj.NewFeature(line, nil, nil)
	p = gj.NewFeature(start, nil, nil)
	fc.AddFeatures(f, p)

	fc.Type = `FeatureCollection`
	geojson, e := gj.Marshal(fc)
	return geojson, e
}
예제 #2
0
func makeFeaturefromRecord(r *Record) string {
	var f *gj.Feature
	lon := gj.Coord(r.Longitude)
	lat := gj.Coord(r.Latitude)
	p := gj.NewPoint(gj.Coordinate{lon, lat})
	id := r.BusID
	props := make(map[string]interface{})
	props["BusName"] = r.BusName
	props["RouteID"] = r.RouteID
	props["TripID"] = r.TripID
	props["TripHeadsign"] = r.TripHeadsign
	props["Service"] = r.Service
	props["LocationUpdated"] = r.LocationUpdated
	f = gj.NewFeature(p, props, id)
	gjstr, err := gj.Marshal(f)
	if err != nil {
		log.Fatal("geojson marshall failed", err)
	}
	return gjstr
}