Пример #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
// Feature returns the Node as a *geojson.Feature.
func (n *Node) Feature() (f *geojson.Feature) {
	// Set the properties.
	properties := make(map[string]interface{}, 6)
	properties["OwnerName"] = n.OwnerName
	properties["Status"] = n.Status

	if len(n.Contact) != 0 {
		properties["Contact"] = n.Contact
	}
	if len(n.PGP) != 0 {
		properties["PGP"] = n.PGP.String()
	}
	if len(n.Details) != 0 {
		properties["Details"] = n.Details
	}
	if n.SourceID != 0 {
		properties["SourceID"] = n.SourceID
	}

	// Create and return the feature.
	return geojson.NewFeature(
		geojson.NewPoint(geojson.Coordinate{
			geojson.CoordType(n.Longitude),
			geojson.CoordType(n.Latitude)}),
		properties,
		n.Addr)
}
Пример #3
0
func SpaceToFeature(space Space) *geojson.Feature {
	infra := spaceToInfra(space)
	lng := geojson.CoordType(infra.Point_.Lng)
	lat := geojson.CoordType(infra.Point_.Lat)
	c := geojson.Coordinate{lng, lat}
	geom := geojson.NewPoint(c)
	prop := map[string]interface{}{spaceValueName: infra.Value_, "createAt": infra.CreateAt_.Unix()}
	return geojson.NewFeature(geom, prop, nil)
}
Пример #4
0
func EncodeMultiPointsIntoLineString(points []*Point) *geojson.Feature {
	var coordinates = make(geojson.Coordinates, len(points))
	for i := range points {
		var c geojson.Coordinate
		c[0] = geojson.CoordType(points[i].Lng)
		c[1] = geojson.CoordType(points[i].Lat)
		coordinates[i] = c
	}
	lineString := geojson.NewLineString(coordinates)
	return geojson.NewFeature(lineString, nil, nil)
}
Пример #5
0
func EncodeMultiPointsIntoFeature(points []*Point) *geojson.Feature {
	var coordinates = make(geojson.Coordinates, len(points))
	for i := range points {
		var c geojson.Coordinate
		c[0] = geojson.CoordType(points[i].Lng)
		c[1] = geojson.CoordType(points[i].Lat)
		coordinates[i] = c
	}
	multiPoint := geojson.NewMultiPoint(coordinates)
	return geojson.NewFeature(multiPoint, nil, nil)
}
Пример #6
0
/**
 *  or free docks, or an error if that was not possible.
 *  @see getFreeDocksNear
 *  @see getBikesNear
 */
func writeDockingStations(w http.ResponseWriter, r *http.Request, filter_type string) {

	lat, _ := strconv.ParseFloat(r.URL.Query().Get("lat"), 64)
	lon, _ := strconv.ParseFloat(r.URL.Query().Get("lon"), 64)
	x0, _ := strconv.ParseFloat(r.URL.Query().Get("x0"), 64)
	y0, _ := strconv.ParseFloat(r.URL.Query().Get("y0"), 64)
	x1, _ := strconv.ParseFloat(r.URL.Query().Get("x1"), 64)
	y1, _ := strconv.ParseFloat(r.URL.Query().Get("y1"), 64)

	var dockingStations DockingStations
	var err error
	var ret []byte

	if filter_type == "bikes" {
		err = dockingStations.GetBikesNear(lat, lon, 4)
	}

	if filter_type == "freedocks" {
		err = dockingStations.GetBikesNear(lat, lon, 4)
	}

	if filter_type == "stations" {
		err = dockingStations.GetStationsInside(x0, y0, x1, y1)
	}

	if err == nil {
		features := []*gj.Feature{}
		for _, dockingStationStatus := range dockingStations.DockingStationStatuses {
			properties := map[string]interface{}{"name": dockingStationStatus.Name, "i": dockingStationStatus.DockId, "bikes": dockingStationStatus.Bikes, "docks": dockingStationStatus.Docks, "updated": dockingStationStatus.Time}
			lat, _ := strconv.ParseFloat(dockingStationStatus.Lat, 64)
			lon, _ := strconv.ParseFloat(dockingStationStatus.Lon, 64)
			p := gj.NewPoint(gj.Coordinate{gj.CoordType(lon), gj.CoordType(lat)})
			f := gj.NewFeature(p, properties, nil)
			features = append(features, f)
		}

		ret, err = json.Marshal(features)
	}

	if err != nil {
		//@todo set return code
		logger.Log("msg", "There was an error retrieving docking stations", "err", err)
		w.Header().Set("Content-Type", "application/json")
		w.Write([]byte("{msg: \"There was an error\"}"))
		return
	}

	w.Header().Set("Server", "bikefinder")
	w.Header().Set("Content-Type", "application/json")
	w.Write(ret)

}
Пример #7
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
}