// 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) }
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) }
/** * 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) }
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 }
// isOtherGeo searches for non-standard geo data in the given json map. It looks for the presence // of lat/lng (and a few variations thereof) or x/y values in the object as well as a distance/radius/accuracy // field and creates a geojson point out of it and returns that, along with a boolean value // representing whether or not it found any geo data in the object. It will also look for // any keys that hold an array of two numbers with a key name that suggests that it might // be a lng/lat array. // // The following keys will be detected as Latitude: // "lat", "latitude" // "y" // // The following keys will be detected as Longitude: // "lng", "lon", "long", "longitude" // "x" // // The following keys will be used to fill the "radius" property of the resulting geojson: // "dist", "distance" // "rad", "radius" // "acc", "accuracy" // // The following keys will be searched for a long/lat pair: // "geo" // "loc" or "location" // "coord", "coords", "coordinate" or "coordinates" func isOtherGeo(o map[string]interface{}) (bool, *Geo) { var foundLat, foundLng, foundDst bool var lat, lng, dst float64 for k, v := range o { switch strings.ToLower(k) { case "lat", "latitude", "y": lat, foundLat = v.(float64) case "lng", "lon", "long", "longitude", "x": lng, foundLng = v.(float64) case "dst", "dist", "distance", "rad", "radius", "acc", "accuracy": dst, foundDst = v.(float64) case "geo", "loc", "location", "coord", "coordinate", "coords", "coordinates": g, ok := v.([]float64) if !ok || len(g) != 2 { break } lng, lat = g[0], g[1] foundLat, foundLng = true, true } } if foundLat && foundLng && latIsValid(lat) && lngIsValid(lng) { p := gj.NewPoint(gj.Coordinate{gj.CoordType(lng), gj.CoordType(lat)}) pstr, _ := gj.Marshal(p) var geo map[string]interface{} json.Unmarshal([]byte(pstr), &geo) debugLog("Found other geo:", geo) g := &Geo{ Geo: geo, } if foundDst { g.Radius = dst } return true, g } return false, nil }
func EncodePoint(point *Point) *geojson.Point { var c geojson.Coordinate c[0] = geojson.CoordType(point.Lng) c[1] = geojson.CoordType(point.Lat) return geojson.NewPoint(c) }