• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang geo.Latlong类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/skypies/geo.Latlong的典型用法代码示例。如果您正苦于以下问题:Golang Latlong类的具体用法?Golang Latlong怎么用?Golang Latlong使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Latlong类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: FixupComplaint

func FixupComplaint(c *types.Complaint, key *datastore.Key) {
	// 0. Snag the key, so we can refer to this object later
	c.DatastoreKey = key.Encode()

	// 1. GAE datastore helpfully converts timezones to UTC upon storage; fix that
	c.Timestamp = date.InPdt(c.Timestamp)

	// 2. Compute the flight details URL, if within 24 days
	age := date.NowInPdt().Sub(c.Timestamp)
	if age < time.Hour*24 {
		// c.AircraftOverhead.Fr24Url = c.AircraftOverhead.PlaybackUrl()

		c.AircraftOverhead.Fr24Url = "http://flightaware.com/live/flight/" +
			c.AircraftOverhead.FlightNumber
		// Or: http://flightaware.com/live/flight/UAL337/history/20151215/ [0655Z/KLAX/KSFO]
		// date is UTC of departure time; might be tricky to guess :/
	}

	// 3. Compute distances, if we have an aircraft
	if c.AircraftOverhead.FlightNumber != "" {
		a := c.AircraftOverhead
		aircraftPos := geo.Latlong{a.Lat, a.Long}
		observerPos := geo.Latlong{c.Profile.Lat, c.Profile.Long}
		c.Dist2KM = observerPos.Dist(aircraftPos)
		c.Dist3KM = observerPos.Dist3(aircraftPos, a.Altitude)
	}
}
开发者ID:skypies,项目名称:complaints,代码行数:27,代码来源:complaint.go


示例2: AirspaceToLocalizedAircraft

func AirspaceToLocalizedAircraft(as *airspace.Airspace, pos geo.Latlong, elev float64) []Aircraft {
	ret := []Aircraft{}

	if as == nil {
		return ret
	}

	for _, ad := range as.Aircraft {
		tp := fdb.TrackpointFromADSB(ad.Msg)
		altitudeDelta := tp.Altitude - elev

		icaoid := string(ad.Msg.Icao24)
		icaoid = strings.TrimPrefix(icaoid, "EE") // fr24 airspaces use this prefix
		icaoid = strings.TrimPrefix(icaoid, "FF") // fa airspaces use this prefix

		a := Aircraft{
			Dist:                pos.DistKM(tp.Latlong),
			Dist3:               pos.Dist3(tp.Latlong, altitudeDelta),
			BearingFromObserver: tp.Latlong.BearingTowards(pos),
			//Id: "someid", // This is set via an IdSpec string below
			Id2:      icaoid,
			Lat:      tp.Lat,
			Long:     tp.Long,
			Track:    tp.Heading,
			Altitude: tp.Altitude,
			Speed:    tp.GroundSpeed,
			// Squawk string
			Radar:        tp.ReceiverName,
			EquipType:    ad.Airframe.EquipmentType,
			Registration: ad.Airframe.Registration,
			Epoch:        float64(tp.TimestampUTC.Unix()),
			Origin:       ad.Schedule.Origin,
			Destination:  ad.Schedule.Destination,
			FlightNumber: ad.Schedule.IataFlight(),
			// Unknown float64
			VerticalSpeed: tp.VerticalRate,
			Callsign:      ad.Msg.Callsign, //"CAL123", //snap.Flight.Callsign,
			// Unknown2 float64
		}

		// Even though we may be parsing an fr24 airspace, generate a skypi idspec (which may break)
		if icaoid != "" {
			a.Id = fdb.IdSpec{IcaoId: icaoid, Time: tp.TimestampUTC}.String()
		}

		// Hack for Surf Air; promote their callsigns into flightnumbers.
		// The goal is to allow them to get past the filter, and be printable etc.
		// There is probably a much better place for this kind of munging. But it needs to happen
		//  regardless of the source of the airspace, so it can't be pushed upstream. (...?)
		if a.FlightNumber == "" && regexp.MustCompile("^URF\\d+$").MatchString(a.Callsign) {
			a.FlightNumber = a.Callsign
		}

		ret = append(ret, a)
	}

	sort.Sort(AircraftByDist3(ret))

	return ret
}
开发者ID:skypies,项目名称:complaints,代码行数:60,代码来源:flightid.go


示例3: GetComplaintPositionsInSpanByIcao

// Leave icaoid as empty string to get all complaints; else limits to that aircraft
func (cdb ComplaintDB) GetComplaintPositionsInSpanByIcao(start, end time.Time, icaoid string) ([]geo.Latlong, error) {
	ret := []geo.Latlong{}

	q := datastore.
		NewQuery(kComplaintKind).
		Project("Profile.Lat", "Profile.Long").
		Filter("Timestamp >= ", start).
		Filter("Timestamp < ", end)

	if icaoid != "" {
		cdb.Infof("Oho, adding id2=%s", icaoid)
		q = q.Filter("AircraftOverhead.Id2 = ", icaoid)
	}

	q = q.Limit(-1)

	var data = []types.Complaint{}
	if _, err := q.GetAll(cdb.Ctx(), &data); err != nil {
		return ret, err
	}

	for _, c := range data {
		// Round off the position data to a certain level of precision
		lat, long := toFixed(c.Profile.Lat, 2), toFixed(c.Profile.Long, 2)
		pos := geo.Latlong{Lat: lat, Long: long}
		if !pos.IsNil() {
			ret = append(ret, pos)
		}
	}

	return ret, nil
}
开发者ID:skypies,项目名称:complaints,代码行数:33,代码来源:complaintlookups.go


示例4: airspaceHandler

func airspaceHandler(w http.ResponseWriter, r *http.Request) {
	client := urlfetch.Client(appengine.NewContext(r))
	pos := geo.Latlong{37.060312, -121.990814}
	str := ""

	if as, err := fr24.FetchAirspace(client, pos.Box(100, 100)); err != nil {
		http.Error(w, fmt.Sprintf("FetchAirspace: %v", err), http.StatusInternalServerError)
		return
	} else {
		oh, debstr := IdentifyOverhead(as, pos, 0.0, AlgoConservativeNoCongestion)
		str += fmt.Sprintf("--{ IdentifyOverhead }--\n -{ OH: %s }-\n\n%s\n", oh, debstr)
	}

	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte("OK\n\n" + str))
}
开发者ID:skypies,项目名称:complaints,代码行数:16,代码来源:flightid.go


示例5: SnapshotAt

func (f Flight) SnapshotAt(t time.Time, pos *geo.Latlong) (*FlightSnapshot, error) {
	if len(f.Track) == 0 {
		return nil, fmt.Errorf("SnapshotAt: found no trackpoints")
	}

	t = t.UTC()
	start, end := f.Track[0].TimestampUTC, f.Track[len(f.Track)-1].TimestampUTC

	if t.Before(start) {
		return nil, fmt.Errorf("SnapshotAt: t<start (t=%s, start=%s)", t, start)
	} else if t.After(end) {
		return nil, fmt.Errorf("SnapshotAt: t>end (t=%s, end=%s)", t, end)
	}

	for i, tp := range f.Track {
		if i == len(f.Track)-1 {
			break
		}
		if tp.TimestampUTC.Before(t) && f.Track[i+1].TimestampUTC.After(t) {
			// Grab the two trackpoints that bracket our time
			snap := &FlightSnapshot{
				F:       f,
				Pos:     f.Track[i],
				NextPos: f.Track[i+1],
			}
			if pos != nil {
				snap.Reference = *pos
				snap.DistToReferenceKM = pos.Dist(f.Track[i].Latlong)
				snap.BearingToReference = float64(int64(pos.BearingTowards(f.Track[i].Latlong)))
			}

			return snap, nil
		}
	}

	return nil, fmt.Errorf("SnapshotAt: fell off the end, bad track ?")
}
开发者ID:skypies,项目名称:flightdb,代码行数:37,代码来源:flightdb.go


示例6: FindOverhead

func (fr *Fr24) FindOverhead(observerPos geo.Latlong, overhead *Aircraft, grabAnything bool) (debug string, err error) {

	debug = fmt.Sprintf("*** FindOverhead for %s, at %s\n", observerPos,
		date.NowInPdt())

	// Create a bounding box that's ~40m square, centred on the input lat,long
	// This is a grievous fudge http://www.movable-type.co.uk/scripts/latlong.html
	lat_20miles := 0.3
	long_20miles := 0.35
	nearby := []Aircraft{}
	if err = fr.ListBbox(observerPos.Lat-lat_20miles, observerPos.Long-long_20miles,
		observerPos.Lat+lat_20miles, observerPos.Long+long_20miles, &nearby); err != nil {
		debug += fmt.Sprintf("Lookup error: %s\n", err)
		return
	}

	for i, a := range nearby {
		aircraftPos := geo.Latlong{a.Lat, a.Long}
		nearby[i].Dist = observerPos.Dist(aircraftPos)
		nearby[i].Dist3 = observerPos.Dist3(aircraftPos, a.Altitude)
		nearby[i].BearingFromObserver = observerPos.BearingTowards(aircraftPos)
	}
	sort.Sort(byDist3(nearby))
	debug += "** nearby list:-\n" + DebugFlightList(nearby)

	filtered := filterAircraft(nearby)
	if len(filtered) == 0 {
		debug += "** all empty after filtering\n"
		return
	}

	debug += "** filtered:-\n" + DebugFlightList(filtered)

	if grabAnything {
		*overhead = filtered[0]
		debug += "** grabbed 1st\n"
	} else {
		// closest plane has to be within 12 km to be 'overhead', and it has
		// to be 4km away from the next-closest
		if filtered[0].Dist3 < 12.0 {
			if (len(filtered) == 1) || (filtered[1].Dist3-filtered[0].Dist3) > 4.0 {
				*overhead = filtered[0]
				debug += "** selected 1st\n"
			} else {
				debug += "** 2nd was too close to 1st\n"
			}
		} else {
			debug += "** 1st was too far away\n"
		}
	}

	return
}
开发者ID:hugoh,项目名称:complaints,代码行数:53,代码来源:fr24.go


示例7: complainByProfile

func (cdb ComplaintDB) complainByProfile(cp types.ComplainerProfile, c *types.Complaint) error {
	client := cdb.HTTPClient()
	overhead := flightid.Aircraft{}

	// Check we're not over a daily cap for this user
	cdb.Debugf("cbe_010", "doing rate limit check")
	s, e := date.WindowForToday()
	if prevKeys, err := cdb.GetComplaintKeysInSpanByEmailAddress(s, e, cp.EmailAddress); err != nil {
		return err
	} else if len(prevKeys) >= KMaxComplaintsPerDay {
		return fmt.Errorf("Too many complaints filed today")
	} else {
		cdb.Debugf("cbe_011", "rate limit check passed (%d); calling FindOverhead", len(prevKeys))
	}

	elev := 0.0
	pos := geo.Latlong{cp.Lat, cp.Long}
	algo := flightid.AlgoConservativeNoCongestion
	if c.Description == "ANYANY" {
		algo = flightid.AlgoGrabClosest
	}

	if as, err := fr24.FetchAirspace(client, pos.Box(64, 64)); err != nil {
		cdb.Errorf("FindOverhead failed for %s: %v", cp.EmailAddress, err)
	} else {
		oh, deb := flightid.IdentifyOverhead(as, pos, elev, algo)
		c.Debug = deb
		if oh != nil {
			overhead = *oh
			c.AircraftOverhead = overhead
		}
	}

	cdb.Debugf("cbe_020", "FindOverhead returned")

	// Contrast with the skypi pathway
	if cp.CallerCode == "WOR004" || cp.CallerCode == "WOR005" {
		asFdb, _ := airspace.Fetch(client, "", pos.Box(60, 60))
		oh3, deb3 := flightid.IdentifyOverhead(asFdb, pos, elev, algo)
		if oh3 == nil {
			oh3 = &flightid.Aircraft{}
		}
		newdebug := c.Debug + "\n*** v2 / fdb testing\n" + deb3 + "\n"
		headline := ""

		if overhead.FlightNumber != oh3.FlightNumber {
			headline = fmt.Sprintf("** * * DIFFERS * * **\n")
		} else {
			// Agree ! Copy over the Fdb IdSpec, and pretend we're living in the future
			headline = fmt.Sprintf("**---- Agrees ! ----**\n")
			c.AircraftOverhead.Id = oh3.Id
		}
		headline += fmt.Sprintf(" * skypi: %s\n * orig : %s\n", oh3, overhead)

		c.Debug = headline + newdebug
	}

	c.Version = kComplaintVersion // Kill this off ?

	c.Profile = cp // Copy the profile fields into every complaint

	// Too much like the last complaint by this user ? Just update that one.
	cdb.Debugf("cbe_030", "retrieving prev complaint")
	if prev, err := cdb.GetNewestComplaintByEmailAddress(cp.EmailAddress); err != nil {
		cdb.Errorf("complainByProfile/GetNewest: %v", err)
	} else if prev != nil && ComplaintsAreEquivalent(*prev, *c) {
		cdb.Debugf("cbe_031", "returned, equiv; about to UpdateComlaint()")
		// The two complaints are in fact one complaint. Overwrite the old one with data from new one.
		Overwrite(prev, c)
		err := cdb.UpdateComplaint(*prev, cp.EmailAddress)
		cdb.Debugf("cbe_032", "updated in place (all done)")
		return err
	}
	cdb.Debugf("cbe_033", "returned, distinct/first; about to put()")

	key := datastore.NewIncompleteKey(cdb.Ctx(), kComplaintKind, cdb.emailToRootKey(cp.EmailAddress))
	_, err := datastore.Put(cdb.Ctx(), key, c)
	cdb.Debugf("cbe_034", "new entity added (all done)")

	// TEMP
	/*
		if debug,err := bksv.PostComplaint(client, cp, *c); err != nil {
			cdb.Infof("BKSV Debug\n------\n%s\n------\n", debug)
			cdb.Infof("BKSV posting error: %v", err)
		} else {
			cdb.Infof("BKSV Debug\n------\n%s\n------\n", debug)
		}
	*/
	return err
}
开发者ID:skypies,项目名称:complaints,代码行数:90,代码来源:update.go


示例8:

var (
	// Retire these three.
	KLatlongSFO    = geo.Latlong{37.6188172, -122.3754281}
	KLatlongSJC    = geo.Latlong{37.3639472, -121.9289375}
	KLatlongSERFR1 = geo.Latlong{37.221516, -121.992987} // This is the centerpoint for maps viewport

	KBoxSnarfingCatchment = KLatlongSFO.Box(125, 125) // The box in which we look for new flights

	// Boxes used in a few reports
	KBoxSFO10K      = KLatlongSFO.Box(12, 12)
	KBoxPaloAlto20K = geo.Latlong{37.433536, -122.1310187}.Box(6, 7)

	KAirports = map[string]geo.Latlong{
		"KSFO": geo.Latlong{37.6188172, -122.3754281},
		"KSJC": geo.Latlong{37.3639472, -121.9289375},
		"KOAK": geo.Latlong{37.7212597, -122.2211489},
	}

	// http://www.myaviationinfo.com/FixState.php?FixState=CALIFORNIA
	KFixes = map[string]geo.Latlong{
		// SERFR2 & WWAVS1
		"SERFR": geo.Latlong{36.0683056, -121.3646639},
		"NRRLI": geo.Latlong{36.4956000, -121.6994000},
		"WWAVS": geo.Latlong{36.7415306, -121.8942333},
		"EPICK": geo.Latlong{36.9508222, -121.9526722},
		"EDDYY": geo.Latlong{37.3264500, -122.0997083},
		"SWELS": geo.Latlong{37.3681556, -122.1160806},
		"MENLO": geo.Latlong{37.4636861, -122.1536583},
		"WPOUT": geo.Latlong{37.1194861, -122.2927417},
		"THEEZ": geo.Latlong{37.5034694, -122.4247528},
		"WESLA": geo.Latlong{37.6643722, -122.4802917},
		"MVRKK": geo.Latlong{37.7369722, -122.4544500},

		// BRIXX
		"CORKK": geo.Latlong{37.7335889, -122.4975500},
		"BRIXX": geo.Latlong{37.6178444, -122.3745278},
		"LUYTA": geo.Latlong{37.2948889, -122.2045528},
		"JILNA": geo.Latlong{37.2488056, -122.1495000},
		"YADUT": geo.Latlong{37.2039889, -122.0232778},

		// BIGSURTWO
		"CARME": geo.Latlong{36.4551833, -121.8797139},
		"ANJEE": geo.Latlong{36.7462861, -121.9648917},
		"SKUNK": geo.Latlong{37.0075944, -122.0332278},
		"BOLDR": geo.Latlong{37.1708861, -122.0761667},

		// BDEGA2
		"LOZIT": geo.Latlong{37.899325, -122.673194},
		"BGGLO": geo.Latlong{38.224589, -122.767506},
		"GEEHH": geo.Latlong{38.453333, -122.428650},
		"MSCAT": geo.Latlong{38.566697, -122.671667},
		"JONNE": geo.Latlong{38.551042, -122.863275},
		"AMAKR": geo.Latlong{39.000000, -123.750000},
		"DEEAN": geo.Latlong{38.349164, -123.302289},
		"MRRLO": geo.Latlong{38.897547, -122.578233},
		"MLBEC": geo.Latlong{38.874772, -122.958989},

		// Things for SFO arrivals
		"HEMAN": geo.Latlong{37.5338500, -122.1733333},
		"NEPIC": geo.Latlong{37.5858944, -122.2968833},

		// Things for SFO departures
		"PORTE": geo.Latlong{37.4897861, -122.4745778},
		"SSTIK": geo.Latlong{37.6783444, -122.3616583},

		// Things for Oceanic
		"PPEGS": geo.Latlong{37.3920722, -122.2817222},
		"ALLBE": geo.Latlong{37.5063889, -127.0000000},
		"ALCOA": geo.Latlong{37.8332528, -125.8345250},
		"CINNY": geo.Latlong{36.1816667, -124.7600000},
		"PAINT": geo.Latlong{38.0000000, -125.5000000},
		"OSI":   geo.Latlong{37.3925000, -122.2813000},
		"PIRAT": geo.Latlong{37.2576500, -122.8633528},
		"PYE":   geo.Latlong{38.0797567, -122.8678275},
		"STINS": geo.Latlong{37.8236111, -122.7566667},
		"HADLY": geo.Latlong{37.4022222, -122.5755556},

		"PONKE": geo.Latlong{37.4588167, -121.9960528},
		"WETOR": geo.Latlong{37.4847194, -122.0571417},

		// Things for SJC/SILCN3
		"VLLEY": geo.Latlong{36.5091667, -121.4402778},
		"GUUYY": geo.Latlong{36.7394444, -121.5411111},
		"SSEBB": geo.Latlong{36.9788889, -121.6425000},
		"GSTEE": geo.Latlong{37.0708333, -121.6716667},
		"KLIDE": geo.Latlong{37.1641667, -121.7130556},
		"BAXBE": geo.Latlong{36.7730556, -121.6263889},
		"APLLE": geo.Latlong{37.0338889, -121.8050000},

		// Randoms
		"PARIY": geo.Latlong{37.3560056, -121.9231222}, // SJC ?
		"ZORSA": geo.Latlong{37.3627583, -122.0500306},

		// Things for East Bay
		"HOPTA": geo.Latlong{37.78501944, -122.154},
		"BOYSS": geo.Latlong{38.02001944, -122.3778639},
		"WNDSR": geo.Latlong{38.681808, -122.478747},
		"WEBRR": geo.Latlong{38.243881, -122.412142},
		"SPAMY": geo.Latlong{39.200661, -122.591042},
		"HUBRT": geo.Latlong{39.040228, -122.568314},
//.........这里部分代码省略.........
开发者ID:skypies,项目名称:geo,代码行数:101,代码来源:sfo.go


示例9: FindAllOverhead

func (fr *Fr24) FindAllOverhead(observerPos geo.Latlong, overhead *flightid.Aircraft, grabAnything bool) (outAll []*Aircraft, outFilt []*Aircraft, debug string, err error) {
	outAll = []*Aircraft{}
	outFilt = []*Aircraft{}

	debug = fmt.Sprintf("*** FindOverhead for %s, at %s\n", observerPos, date.NowInPdt())
	debug += fmt.Sprintf("* url: http://%s%s?array=1&bounds=%s\n", fr.host, kListUrlPath, "...")

	// Create a bounding box that's ~40m square, centred on the input lat,long
	// This is a grievous fudge http://www.movable-type.co.uk/scripts/latlong.html
	lat_20miles := 0.3
	long_20miles := 0.35
	nearby := []Aircraft{}
	if err = fr.ListBbox(observerPos.Lat-lat_20miles, observerPos.Long-long_20miles,
		observerPos.Lat+lat_20miles, observerPos.Long+long_20miles, &nearby); err != nil {
		debug += fmt.Sprintf("Lookup error: %s\n", err)
		return
	}

	for i, a := range nearby {
		// Hack for Surf Air; promote callsigns into (invalid_ flightnumbers, so they don't get stripped
		if a.FlightNumber == "" && regexp.MustCompile("^URF\\d+$").MatchString(a.Callsign) {
			nearby[i].FlightNumber = a.Callsign
		} else if a.FlightNumber != "" {
			if _, _, err := fdb.ParseIata(a.FlightNumber); err != nil {
				debug += "** saw bad flightnumber '" + a.FlightNumber + "' from fr24\n"
				nearby[i].FlightNumber = ""
			}
		}

		aircraftPos := geo.Latlong{a.Lat, a.Long}
		nearby[i].Dist = observerPos.Dist(aircraftPos)
		nearby[i].Dist3 = observerPos.Dist3(aircraftPos, a.Altitude)
		nearby[i].BearingFromObserver = observerPos.BearingTowards(aircraftPos)
	}
	sort.Sort(byDist3(nearby))
	debug += "** nearby list:-\n" + DebugFlightList(nearby)

	filtered := filterAircraft(nearby)
	if len(filtered) == 0 {
		debug += "** all empty after filtering\n"
		return
	}

	for i, _ := range nearby {
		outAll = append(outAll, &nearby[i])
	}
	for i, _ := range filtered {
		outFilt = append(outFilt, &filtered[i])
	}

	debug += "** filtered:-\n" + DebugFlightList(filtered)

	if grabAnything {
		filtered[0].IntoFlightIdAircraft(overhead)
		debug += "** grabbed 1st\n"
	} else {
		// closest plane has to be within 12 km to be 'overhead', and it has
		// to be 4km away from the next-closest
		if filtered[0].Dist3 < 12.0 {
			if (len(filtered) == 1) || (filtered[1].Dist3-filtered[0].Dist3) > 4.0 {
				filtered[0].IntoFlightIdAircraft(overhead)
				debug += "** selected 1st\n"
			} else {
				debug += "** 2nd was too close to 1st\n"
			}
		} else {
			debug += "** 1st was too far away\n"
		}
	}

	return
}
开发者ID:skypies,项目名称:flightdb,代码行数:72,代码来源:fr24.go



注:本文中的github.com/skypies/geo.Latlong类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang date.NowInPdt函数代码示例发布时间:2022-05-28
下一篇:
Golang gae.FlightDB类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap