// packs location into the next (usually first) 6 cells of the fields array public void packCoord(GeoCoord loc) { // $PMGNWPL,3339.889,N,11736.283,W,0000155,M,WPT001,this is comment,a*7E double Lat = loc.Lat; string sDir = Lat < 0 ? "S" : "N"; double aLat = Math.Abs(Lat); int iLat = (int)Math.Floor(aLat); double latMin = aLat - iLat; double latMinM = Math.Round(latMin * 60.0d, 3); string format = latMinM < 10.0 ? "{0:D2}0{1:F3}" :"{0:D2}{1:F3}"; string sLat = string.Format(format, iLat, latMinM); fields.Add(sLat); fields.Add(sDir); double Lng = loc.Lng; sDir = Lng < 0 ? "W" : "E"; double aLng = Math.Abs(Lng); int iLng = (int)Math.Floor(aLng); double lngMin = aLng - iLng; double lngMinM = Math.Round(lngMin * 60.0d, 3); format = lngMinM < 10.0 ? "{0:D3}0{1:F3}" :"{0:D3}{1:F3}"; string sLng = string.Format(format, iLng, lngMinM); fields.Add(sLng); fields.Add(sDir); int Elev = (int)loc.Elev; fields.Add("" + Elev); fields.Add("M"); }
private bool m_triedReload = false; // limits reload attempts #endregion Fields #region Constructors public TileTerra(TileSetTerra ts, Scale tileScale, GeoCoord topLeft, GeoCoord bottomRight) { m_tileSet = ts; m_tileScale = tileScale; m_topLeft = topLeft.Clone(); m_bottomRight = bottomRight.Clone(); //LibSys.StatusBar.Trace("TileTerra() topLeft=" + m_topLeft.ToString() + " bottomRight=" + m_bottomRight.ToString()); }
public Vehicle(GeoCoord loc, string name, string sym, string source, string url, string desc) : base("", loc) { m_label = name; m_sym = sym; m_source = source; m_url = url; m_desc = desc; Image = null; tick(); // set Name }
public bool sameAs(object obj) { if (obj == null) { return(false); } GeoCoord other = (GeoCoord)obj; other.Normalize(); Normalize(); return(other.Lat == m_Y && other.Lng == m_X); // && other.Elev == m_H; }
// tolerance 0.0001 degree = 10 meters public bool almostAs(object obj, double tolerance) { if (obj == null) { return(false); } GeoCoord other = (GeoCoord)obj; other.Normalize(); Normalize(); return(Math.Abs(other.Lat - m_Y) <= tolerance && Math.Abs(other.Lng - m_X) <= tolerance); // && other.Elev == m_H; }
public Landmark(string name, GeoCoord location, string landmarkType) { LiveObjectType = LiveObjectTypes.LiveObjectTypeLandmark; Location = location; Name = name; LandmarkType = landmarkType; brushFont = Project.landmarkFontBrush; brushBackground = Project.landmarkBackgroundBrush; penMain = Project.landmarkPen; penUnderline = Project.landmarkPen; }
public City(XmlNode node) // may throw an exception if XML node is not right { double lng = 0.0d; double lat = 0.0d; foreach (XmlNode pnode in node.ChildNodes) { switch (pnode.Name) { case "p4": lat = Convert.ToDouble(pnode.InnerText); break; case "p5": lng = Convert.ToDouble(pnode.InnerText); break; case "p12": string tmpDsg = pnode.InnerText; if (tmpDsg != null && (tmpDsg.Equals("C") || tmpDsg.Equals("A"))) { m_dsg = tmpDsg; } break; case "p13": m_importance = Convert.ToInt32(pnode.InnerText); break; case "p14": m_country = pnode.InnerText; break; case "p15": m_state = pnode.InnerText; break; case "p16": m_county = pnode.InnerText; break; case "p17": m_population = Convert.ToInt32(pnode.InnerText); break; case "p25": m_name = pnode.InnerText; break; } } m_location = new GeoCoord(lng, lat); CleanName(); }
public override bool Equals(object obj) { if (obj == null) { return(false); } GeoCoord other = (GeoCoord)obj; //other.normalize(); //normalize(); return(other.Lat == m_Y && other.Lng == m_X && other.Elev == m_H); }
// returns bearing in rads. To get degrees, multiply by 180.0d / Math.PI public double bearing(GeoCoord nextLoc) { double Lon1 = this.Lng * Math.PI / 180.0d; double Lon2 = nextLoc.Lng * Math.PI / 180.0d; double Lat1 = this.Lat * Math.PI / 180.0d; double Lat2 = nextLoc.Lat * Math.PI / 180.0d; double y = Math.Sin(Lon1 - Lon2) * Math.Cos(Lat2); double x = Math.Cos(Lat1) * Math.Sin(Lat2) - Math.Sin(Lat1) * Math.Cos(Lat2) * Math.Cos(Lon1 - Lon2); // from http://www.movable-type.co.uk/scripts/LatLong.html if (Math.Sin(Lon2 - Lon1) > 0.0) { return(Math.Atan2(-y, x)); } else { return(2.0d * Math.PI - Math.Atan2(y, x)); } /* * // see http://www.malaysiagis.com/related_technologies/gps/article3.cfm for the formula and some code * // see http://www.fcaglp.unlp.edu.ar/~esuarez/gmt/1997/0148.html for more * double ret = 0.0d; * * double rad_bearing; * * double rad_dist = Math.Acos(Math.Sin(Lat1) * Math.Sin(Lat2) + Math.Cos(Lat1) * Math.Cos(Lat2) * Math.Cos(Lon1 - Lon2)); * * if (Math.Sin(Lon2 - Lon1) > 0.0) * { * double t1 = Math.Sin(Lat2) - Math.Sin(Lat1) * Math.Cos(rad_dist); * double t2 = Math.Cos(Lat1) * Math.Sin(rad_dist); * double t3 = t1 / t2; * double t4 = Math.Atan(-t3 / Math.Sqrt(-t3 * t3 + 1)) + 2 * Math.Atan(1); * rad_bearing = t4; * } * else * { * double t1 = Math.Sin(Lat2) - Math.Sin(Lat1) * Math.Cos(rad_dist); * double t2 = Math.Cos(Lat1) * Math.Sin(rad_dist); * double t3 = t1 / t2; * double t4 = -t3 * t3 + 1; * double t5 = 2.0d * Math.PI - (Math.Atan(-t3 / Math.Sqrt(-t3 * t3 + 1)) + 2 * Math.Atan(1)); * rad_bearing = t5; * } * * ret = rad_bearing; * * return ret; */ }
public City(string name, GeoCoord loc, string country, string state, string county, int population, int importance, string dsg) : base(name, loc) { m_country = country; m_state = state; m_county = county; m_population = population; m_importance = importance; if (dsg != null && dsg.Length > 0) { m_dsg = dsg; } CleanName(); }
/// <summary> /// returns a formatted string suitable for popups /// </summary> /// <returns></returns> public string ToStringPopup() { string ret = " -- " + type; ret += " on: " + Project.zuluToLocal(dateTime).ToShortDateString(); ret += " by: " + finder; if (logWptLat != 0.0f || logWptLon != 0.0f) { GeoCoord loc = new GeoCoord(logWptLon, logWptLat); ret += " at: " + loc.ToString(); } return(ret); }
public Earthquake(GeoCoord loc, double magn, DateTime dateTime, string quality, string comment, string source, string url) : base("", loc) { this.LiveObjectType = LiveObjectTypes.LiveObjectTypeEarthquake; m_pixelRadius = MIN_EQ_PIXEL_RADIUS + 2; N_LABEL_POSITIONS = 12; m_magn = magn; m_dateTime = dateTime; // always UTC m_quality = quality; m_source = source; m_url = url; Name = getLabel(false); //"" + m_magn + " - " + m_dateTime; }
// Use index from TileSetTerra.m_scale to define desired scale. // if scaleIndexHint==-1 the elev is used to find the best matching scale. See TileSetTerra.calcScaleIndex for more. public TileSetTerraLayout(GeoCoord coverageTopLeft, GeoCoord coverageBottomRight, double elev, int scaleIndexHint, Theme theme, bool themeIsColor) { m_coverageTopLeft = coverageTopLeft; m_coverageBottomRight = coverageBottomRight; m_curTheme = theme; m_curThemeColor = themeIsColor; double lng = (coverageTopLeft.Lng + coverageBottomRight.Lng) / 2; double lat = (coverageTopLeft.Lat + coverageBottomRight.Lat) / 2; m_coverageCenter = new GeoCoord(lng, lat); int scaleIndex; Scale tileScale; isValid = TileSetTerra.calcScaleIndex(m_curTheme, elev, scaleIndexHint, out scaleIndex, out tileScale); m_tileScale = tileScale; }
public XmlNode Point(GeoCoord loc, bool clampedToGround) { XmlNode ret = ownerDoc.documentNode.OwnerDocument.CreateElement("Point"); this.elementNode.AppendChild(ret); XmlNode node = elementNode.OwnerDocument.CreateElement("altitudeMode"); node.InnerText = clampedToGround ? "clampedToGround" : "absolute"; ret.AppendChild(node); node = elementNode.OwnerDocument.CreateElement("coordinates"); node.InnerText = String.Format("{0:F5},{1:F5},{2:F1}\n", loc.Lng, loc.Lat, loc.Elev); ret.AppendChild(node); return(ret); }
public void splitLeg(Leg leg, GeoCoord midLoc) { Distance dFrom = leg.WptFrom.distanceFrom(midLoc); Distance dTo = leg.WptTo.distanceFrom(midLoc); double ratio = dFrom.Meters / (dFrom.Meters + dTo.Meters); DateTime dt = leg.WptFrom.DateTime.AddTicks((long)(leg.Duration.Ticks * ratio)); if (leg.Duration.TotalSeconds > 60.0d) { dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); // round to a second } // assuming that midLoc has been already "new" and will attach to the new waypoint: Waypoint wpt = new Waypoint(midLoc, dt, leg.WptFrom.LiveObjectType, leg.WptFrom.TrackId, "", leg.WptFrom.Source, ""); insertWaypoint(wpt); rebuildTrackBoundaries(); }
// closest is SortedList of string (name) by key=double (distance meters) public DlgFavoritesAddTo(CamPos camPos, SortedList closest, MenuItem parentMenuItem, EventHandler eventHandler) { m_camPos = camPos; m_parentMenuItem = parentMenuItem; m_eventHandler = eventHandler; InitializeComponent(); GeoCoord loc = new GeoCoord(m_camPos); Distance camHD = new Distance(m_camPos.H); int unitsCompl = camHD.UnitsCompl; locationLabel.Text = "Location: " + loc.ToString() + " / Camera at " + camHD.ToString(unitsCompl); nameComboBox.Text = m_camPos.Name; for(int i=0; i < closest.Count && i < 20 ;i++) { string name = ((LiveObject)closest.GetByIndex(i)).Name; nameComboBox.Items.Add(name); } Project.setDlgIcon(this); }
public GeoCoord subtract(GeoCoord a, bool spans180) { double x = a.x(); double dx = m_X - x; if (spans180) { // dx < 360.0 && Math.Abs(dx) > 180.0) { if (x > 90.0 && m_X < -90) { x -= 360.0; } else if (m_X > 90.0 && x < -90) { x += 360.0; } dx = m_X - x; } double dy = m_Y - a.y(); double dz = m_H - a.h(); return(new GeoCoord(dx, dy, dz)); }
public Place(XmlNode node) // may throw an exception if XML node is not right { double lng = 0.0d; double lat = 0.0d; foreach (XmlNode pnode in node.ChildNodes) { switch (pnode.Name) { case "p4": lat = Convert.ToDouble(pnode.InnerText); break; case "p5": lng = Convert.ToDouble(pnode.InnerText); break; case "p12": m_dsg = pnode.InnerText; break; case "p13": m_importance = Convert.ToInt32(pnode.InnerText); break; case "p25": m_name = pnode.InnerText; break; } } m_location = new GeoCoord(lng, lat); CleanName(); AdjustImportance(); m_code = codeByDsg(m_dsg); //LibSys.StatusBar.Trace("Place(xml): - " + this); }
// returns bearing in rads. To get degrees, multiply by 180.0d / Math.PI public double bearing(GeoCoord nextLoc) { double Lon1 = this.Lng * Math.PI / 180.0d; double Lon2 = nextLoc.Lng * Math.PI / 180.0d; double Lat1 = this.Lat * Math.PI / 180.0d; double Lat2 = nextLoc.Lat * Math.PI / 180.0d; double y = Math.Sin(Lon1-Lon2) * Math.Cos(Lat2); double x = Math.Cos(Lat1) * Math.Sin(Lat2) - Math.Sin(Lat1) * Math.Cos(Lat2) * Math.Cos(Lon1 - Lon2); // from http://www.movable-type.co.uk/scripts/LatLong.html if (Math.Sin(Lon2 - Lon1) > 0.0) { return(Math.Atan2(-y, x)); } else { return(2.0d * Math.PI - Math.Atan2(y, x)); } /* // see http://www.malaysiagis.com/related_technologies/gps/article3.cfm for the formula and some code // see http://www.fcaglp.unlp.edu.ar/~esuarez/gmt/1997/0148.html for more double ret = 0.0d; double rad_bearing; double rad_dist = Math.Acos(Math.Sin(Lat1) * Math.Sin(Lat2) + Math.Cos(Lat1) * Math.Cos(Lat2) * Math.Cos(Lon1 - Lon2)); if (Math.Sin(Lon2 - Lon1) > 0.0) { double t1 = Math.Sin(Lat2) - Math.Sin(Lat1) * Math.Cos(rad_dist); double t2 = Math.Cos(Lat1) * Math.Sin(rad_dist); double t3 = t1 / t2; double t4 = Math.Atan(-t3 / Math.Sqrt(-t3 * t3 + 1)) + 2 * Math.Atan(1); rad_bearing = t4; } else { double t1 = Math.Sin(Lat2) - Math.Sin(Lat1) * Math.Cos(rad_dist); double t2 = Math.Cos(Lat1) * Math.Sin(rad_dist); double t3 = t1 / t2; double t4 = -t3 * t3 + 1; double t5 = 2.0d * Math.PI - (Math.Atan(-t3 / Math.Sqrt(-t3 * t3 + 1)) + 2 * Math.Atan(1)); rad_bearing = t5; } ret = rad_bearing; return ret; */ }
public LiveObject(string name, GeoCoord loc) { m_name = name; m_location = loc; }
/// <summary> /// resets boundaries (TopLeft, BottomRight) so that newly added waypoints' boundaries are calculated /// useful for reading in .loc files /// </summary> public static void resetBoundaries() { m_topLeft = new GeoCoord(180.0d, -90.0d); m_bottomRight = new GeoCoord(-180.0d, 90.0d); }
// may throw an exception if the data is not right public Earthquake(string[] infos) { this.LiveObjectType = LiveObjectTypes.LiveObjectTypeEarthquake; m_pixelRadius = MIN_EQ_PIXEL_RADIUS + 2; N_LABEL_POSITIONS = 12; /* infos: 0 '2002/09/13 22:28:31' infos: 1 '13.10N' infos: 2 '93.11E' infos: 3 '33.0' infos: 4 '6.5' infos: 5 'A' infos: 6 'ANDAMAN ISLANDS, INDIA REGION' infos: 7 'http://neic.usgs.gov/neis/bulletin/neic_jabw.html' infos: 8 'bulletin' */ // time may be PDT from SCEC or HST from Hawaii - see EarthquakesCache:processQuakes0() bool notUtc = false; double zoneShift = 0.0d; if(infos[0].EndsWith(" PDT")) { notUtc = true; zoneShift = 8.0d; } else if(infos[0].EndsWith(" HST")) { notUtc = true; zoneShift = 10.0d; // this one (10.0d) works in winter (tested Jan 30th 2005) if(System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now)) { zoneShift = 11.0d; // supposedly works in summer (TODO: test it!) } } if(notUtc) { string sTime = infos[0].Substring(0, infos[0].Length - 4); DateTime localTime = Convert.ToDateTime(sTime); // convert local time to UTC (with Daylight shift): //DaylightTime daylightTime = new DaylightTime(...); //if(System.TimeZone.IsDaylightSavingTime(localTime, daylightTime)) if(System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(localTime)) { m_dateTime = localTime.AddHours(zoneShift - 1.0d); // to zulu, with daylight savings } else { m_dateTime = localTime.AddHours(zoneShift); // to zulu } } else // UTC from NEIC { m_dateTime = Convert.ToDateTime(infos[0]); // already zulu } double lat; double lng; double depth; if(infos[1].ToLower().EndsWith("s") || infos[1].ToLower().EndsWith("n")) { lat = Convert.ToDouble(infos[1].Substring(0, infos[1].Length - 1)); if(infos[1].ToLower().EndsWith("s")) { lat = -lat; } lng = Convert.ToDouble(infos[2].Substring(0, infos[2].Length - 1)); if(infos[2].ToLower().EndsWith("w")) { lng = -lng; } } else { lat = Convert.ToDouble(infos[1]); lng = Convert.ToDouble(infos[2]); } try { depth = Convert.ToDouble(infos[3]) * 1000.0d; } catch (Exception e) { depth = 0.0d; } m_location = new GeoCoord(lng, lat, -depth); try { m_magn = Convert.ToDouble(infos[4]); } catch (Exception e) { m_magn = 0.0d; } m_quality = infos[5]; m_comment = infos[6]; m_url = infos[7]; m_source = infos[8]; Name = getLabel(false);; }
protected void setCoordFields(GeoCoord location) { speedLabel.Visible = false; speedTextBox.Visible = false; speedUnitsLabel.Visible = false; m_cameraManager.MarkLocation(location, 0); if(Project.coordStyle == 3) // UTM? { coordFormatLabel.Text = "type like\r\n11S 432345E 3712345N"; latLabel.Text = "* UTM:"; lngLabel.Visible = false; longitudeTextBox.Visible = false; latitudeTextBox.Text = m_latText = location.ToString(); m_lngText = longitudeTextBox.Text; // will be a part of comparison later } else { coordFormatLabel.Text = "type like 117,33.355 -\r\nfirst comma, then dot"; latLabel.Text = "* Latitude:"; lngLabel.Visible = true; longitudeTextBox.Visible = true; latitudeTextBox.Text = m_latText = "" + GeoCoord.latToString(location.Lat, Project.coordStyle, true, true); longitudeTextBox.Text = m_lngText = "" + GeoCoord.lngToString(location.Lng, Project.coordStyle, true, true); } Distance elevDist = new Distance(location.Elev); int unitsCompl = elevDist.UnitsCompl; elevationTextBox.Text = m_elevText = elevDist.toStringN(unitsCompl); elevationUnitsLabel.Text = elevDist.toStringU(unitsCompl); }
public DlgMakeWaypoint(CameraManager cameraManager, PhotoDescr photoDescr, Waypoint wpt) : this(cameraManager) { this.TopMost = true; if(wpt == null) { m_clickLocation = m_cameraManager.Location.Clone(); m_clickLocation.Elev = 0.0d; } else { m_clickLocation = wpt.Location.Clone(); elevLabel.Text = wpt.TrackId == -1 ? "Elevation:" : "Altitude"; } setCoordFields(m_clickLocation); m_photoDescr = photoDescr; this.waypointNameTextBox.Text = m_photoDescr.imageName; this.urlTextBox.Text = m_photoDescr.imageUrl; this.detailTextBox.Text = m_photoDescr.imageSource; this.timePicker.dateTime = m_photoDescr.DTOrig; // all we can realistically change here is coordinates and elevation, so disable other conrols: this.symbolTextBox.Enabled = false; this.waypointNameTextBox.Enabled = false; this.waypointTypeComboBox.Enabled = false; this.urlNameTextBox.Enabled = false; this.urlTextBox.Enabled = false; this.detailTextBox.Enabled = false; this.commentTextBox.Enabled = false; //this.timePicker.Enabled = false; Project.setDlgIcon(this); waypointNameTextBox.Focus(); }
public void split(GeoCoord midLoc) { GeoCoord midLocWithAlt = new GeoCoord(midLoc); midLocWithAlt.Elev = m_wptFrom.Location.Elev; m_track.splitLeg(this, midLocWithAlt); }
public GeoCoord(GeoCoord loc) { m_X = loc.Lng; m_Y = loc.Lat; m_H = loc.Elev; }
public GeoCoord add(GeoCoord a) { return(new GeoCoord(m_X + a.x(), m_Y + a.y(), m_H + a.h())); }
public Distance distanceFrom(GeoCoord from) { /* old version: * double x = this.subtract(from, false).x(); * double y = this.subtract(from, false).y(); * * // a grad square is cos(latitude) thinner, we need latitude in radians: * double midLatRad = (this.add(from).y() / 2.0d) * Math.PI / 180.0d; * double latitudeFactor = Math.Cos(midLatRad); * double xMeters = Math.Abs(Distance.METERS_PER_DEGREE * x * latitudeFactor); * double yMeters = Math.Abs(Distance.METERS_PER_DEGREE * y); * Distance distance = new Distance(Math.Sqrt(xMeters*xMeters + yMeters*yMeters)); */ /* * // see http://www.malaysiagis.com/related_technologies/gps/article3.cfm for the formula and some code * // see http://www.fcaglp.unlp.edu.ar/~esuarez/gmt/1997/0148.html for more * double Lon1 = this.Lng; * double Lon2 = from.Lng; * double Lat1 = this.Lat; * double Lat2 = from.Lat; * * double rad_dist = Math.Acos(Math.Sin(Lat1) * Math.Sin(Lat2) + Math.Cos(Lat1) * Math.Cos(Lat2) * Math.Cos(Lon1 - Lon2)); * // to convert from radians to nautical miles, use the formula NM = rad_dist × 3437.7387. Then you can convert to land miles or kilometers. * //double meters = rad_dist * rEarth; //3437.7387d * Distance.METERS_PER_NAUTICAL_MILE; */ /* * double p1 = Math.Cos(Lat) * Math.Cos(Lng) * Math.Cos(from.Lat) * Math.Cos(from.Lng); * double p2 = Math.Cos(Lat) * Math.Sin(Lng) * Math.Cos(from.Lat) * Math.Sin(from.Lng); * double p3 = Math.Sin(Lat) * Math.Sin(from.Lat); * * double rad_dist = Math.Acos(p1 + p2 + p3); */ /* * double lon1 = this.Lng; * double lon2 = from.Lng; * double lat1 = this.Lat; * double lat2 = from.Lat; * * double dlon = (lon2 - lon1); * double dlat = (lat2 - lat1); * * double a = (Math.Sin(dlat/2))*(Math.Sin(dlat/2)) + * (Math.Cos(lat1) * Math.Cos(lat2) * (Math.Sin(dlon/2))) * * (Math.Cos(lat1) * Math.Cos(lat2) * (Math.Sin(dlon/2))); * * double rad_dist = 2 * Math.Asin(Math.Min(1.0,Math.Sqrt(a))); */ /* * // from http://www.irbs.com/lists/navigation/0111/0022.html * // The haversine distance formula goes as follows: * double lon1 = this.Lng; * double lon2 = from.Lng; * double lat1 = this.Lat; * double lat2 = from.Lat; * * double DLat = lat2 - lat1; * double DLo = lon2 - lon1; * * double p1 = Math.Sin(DLat/2); * double p2 = Math.Sin(DLo/2); * double A = p1 * p1 + Math.Cos(lat2) * Math.Cos(lat1) * p2 * p2; * * double meters = EARTH_RADIUS * Math.Asin (Math.Sqrt(A)); */ // from http://www.movable-type.co.uk/scripts/LatLong.html double lon1 = this.Lng * Math.PI / 180.0d; double lon2 = from.Lng * Math.PI / 180.0d; double lat1 = this.Lat * Math.PI / 180.0d; double lat2 = from.Lat * Math.PI / 180.0d; double dLat = lat2 - lat1; double dLong = lon2 - lon1; double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Sin(dLong / 2) * Math.Sin(dLong / 2); double c = 2.0d * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0d - a)); double meters = EARTH_RADIUS * c; Distance distance = new Distance(meters); return(distance); }
public GeoCoord subtract(GeoCoord a, bool spans180) { double x = a.x(); double dx = m_X - x; if(spans180) { // dx < 360.0 && Math.Abs(dx) > 180.0) { if(x > 90.0 && m_X < -90) { x -= 360.0; } else if(m_X > 90.0 && x < -90) { x += 360.0; } dx = m_X - x; } double dy = m_Y - a.y(); double dz = m_H - a.h(); return new GeoCoord(dx, dy, dz); }
public void translate(GeoCoord to) { m_X = to.x(); m_Y = to.y(); m_H = to.h(); }
public Earthquake(string[] infos) // may throw an exception if the data is not right { this.LiveObjectType = LiveObjectTypes.LiveObjectTypeEarthquake; m_pixelRadius = MIN_EQ_PIXEL_RADIUS + 2; N_LABEL_POSITIONS = 12; /* * infos: 0 '2002/09/13 22:28:31' * infos: 1 '13.10N' * infos: 2 '93.11E' * infos: 3 '33.0' * infos: 4 '6.5' * infos: 5 'A' * infos: 6 'ANDAMAN ISLANDS, INDIA REGION' * infos: 7 'http://neic.usgs.gov/neis/bulletin/neic_jabw.html' * infos: 8 'bulletin' */ // time may be PDT from SCEC or HST from Hawaii - see EarthquakesCache:processQuakes0() bool notUtc = false; double zoneShift = 0.0d; if (infos[0].EndsWith(" PDT")) { notUtc = true; zoneShift = 8.0d; } else if (infos[0].EndsWith(" HST")) { notUtc = true; zoneShift = 10.0d; // this one (10.0d) works in winter (tested Jan 30th 2005) if (System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now)) { zoneShift = 11.0d; // supposedly works in summer (TODO: test it!) } } if (notUtc) { string sTime = infos[0].Substring(0, infos[0].Length - 4); DateTime localTime = Convert.ToDateTime(sTime); // convert local time to UTC (with Daylight shift): //DaylightTime daylightTime = new DaylightTime(...); //if(System.TimeZone.IsDaylightSavingTime(localTime, daylightTime)) if (System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(localTime)) { m_dateTime = localTime.AddHours(zoneShift - 1.0d); // to zulu, with daylight savings } else { m_dateTime = localTime.AddHours(zoneShift); // to zulu } } else // UTC from NEIC { m_dateTime = Convert.ToDateTime(infos[0]); // already zulu } double lat; double lng; double depth; if (infos[1].ToLower().EndsWith("s") || infos[1].ToLower().EndsWith("n")) { lat = Convert.ToDouble(infos[1].Substring(0, infos[1].Length - 1)); if (infos[1].ToLower().EndsWith("s")) { lat = -lat; } lng = Convert.ToDouble(infos[2].Substring(0, infos[2].Length - 1)); if (infos[2].ToLower().EndsWith("w")) { lng = -lng; } } else { lat = Convert.ToDouble(infos[1]); lng = Convert.ToDouble(infos[2]); } try { depth = Convert.ToDouble(infos[3]) * 1000.0d; } catch (Exception e) { depth = 0.0d; } m_location = new GeoCoord(lng, lat, -depth); try { m_magn = Convert.ToDouble(infos[4]); } catch (Exception e) { m_magn = 0.0d; } m_quality = infos[5]; m_comment = infos[6]; m_url = infos[7]; m_source = infos[8]; Name = getLabel(false);; }
public CustomMap(string name, GeoCoord loc) : base(name, loc) { }
public City parseCityString(string str) { //System.Console.WriteLine(str); string name = str.Substring(0, 49).Trim(); //System.Console.WriteLine("\"" + name + "\""); string country = "US"; //System.Console.WriteLine("\"" + country + "\""); string state = str.Substring(54, 3).Trim(); //System.Console.WriteLine("\"" + state + "\""); string county = str.Substring(58, 19).Trim(); //System.Console.WriteLine("\"" + county + "\""); string latDir = str.Substring(83, 1); //System.Console.WriteLine("\"" + latDir + "\""); string longDir = str.Substring(93, 1); //System.Console.WriteLine("\"" + longDir + "\""); int importance = 0; //System.Console.WriteLine("\"" + importance + "\""); string dsg = str.Substring(52, 1).Trim();; //System.Console.WriteLine("\"" + dsg + "\""); double[] a = new double[8]; try { a[0] = Convert.ToDouble(str.Substring(77, 2)); a[1] = Convert.ToDouble(str.Substring(79, 2)); a[2] = Convert.ToDouble(str.Substring(81, 2)); a[3] = Convert.ToDouble(str.Substring(86, 3)); a[4] = Convert.ToDouble(str.Substring(89, 2)); a[5] = Convert.ToDouble(str.Substring(91, 2)); a[6] = Convert.ToDouble(str.Substring(141).Replace(' ', '0')); } catch (Exception ee) { LibSys.StatusBar.Trace("line " + m_lineno + " of " + m_fileName + ee.Message); } /* * int i; * for(i=0; i < a.length ;i++) * System.Console.WriteLine("" + i + " " + a[i]); */ GeoCoord loc; if (Project.EqualsIgnoreCase("W", longDir) && Project.EqualsIgnoreCase("N", latDir)) { loc = new GeoCoord(-a[3], -a[4], -a[5], a[0], a[1], a[2]); } else if (Project.EqualsIgnoreCase("W", longDir) && Project.EqualsIgnoreCase("S", latDir)) { loc = new GeoCoord(-a[3], -a[4], -a[5], -a[0], -a[1], -a[2]); } else if (Project.EqualsIgnoreCase("E", longDir) && Project.EqualsIgnoreCase("S", latDir)) { loc = new GeoCoord(a[3], a[4], a[5], -a[0], -a[1], -a[2]); } else { // "W" "S" loc = new GeoCoord(a[3], a[4], a[5], a[0], a[1], a[2]); } City city = new City(name, loc, country, state, county, (int)a[6], importance, dsg); //if(name.StartsWith("Santa")) //{ // LibSys.StatusBar.Trace("line " + m_lineno + " of " + m_fileName + " " + city.ToString()); //} return(city); }
protected virtual void act() { double lng; double lat; double elev; bool allcool = validateCoord(out lng, out lat, out elev); if(waypointNameTextBox.Text.Length == 0) { waypointNameLabel.ForeColor = Color.Red; allcool = false; } else { waypointNameLabel.ForeColor = Color.Black; } DateTime dateTime = timePicker.isActive ? Project.localToZulu(timePicker.dateTime) : DateTime.MinValue; if(allcool) { try { GeoCoord location = m_clickLocation; if(!m_latText.Equals(latitudeTextBox.Text) || !m_lngText.Equals(longitudeTextBox.Text) || !m_elevText.Equals(elevationTextBox.Text)) { location = new GeoCoord(lng, lat, elev); } location.Normalize(); LiveObjectTypes type = LiveObjectTypes.LiveObjectTypeWaypoint; bool isFound = false; switch(waypointTypeComboBox.SelectedIndex) { case 0: type = LiveObjectTypes.LiveObjectTypeWaypoint; break; case 1: type = LiveObjectTypes.LiveObjectTypeGeocache; break; case 2: type = LiveObjectTypes.LiveObjectTypeGeocache; isFound = true; break; } string wptName = waypointNameTextBox.Text; Waypoint wpt = new Waypoint(location, dateTime, type, -1L, wptName, "", ""); wpt.Found = isFound; wpt.UrlName = urlNameTextBox.Text.Trim(); wpt.Sym = symbolTextBox.Text.Trim(); wpt.Comment = commentTextBox.Text.Trim(); wpt.Desc = detailTextBox.Text.Trim(); string url = urlTextBox.Text.Trim(); if(url.Length > 0 && !url.Equals("http://")) // if something meaningful has been entered { wpt.Url = url; } if(m_photoDescr != null) { wpt.ThumbSource = m_photoDescr.imageThumbSource; wpt.ThumbImage = PhotoDescr.rebuildThumbnailImage(wpt.ThumbSource); wpt.ThumbPosition = Project.thumbPosition; wpt.imageWidth = m_photoDescr.Width; wpt.imageHeight = m_photoDescr.Height; wpt.PhotoTimeShift = new TimeSpan(0L); } WaypointsCache.WaypointsAll.Add(wpt); WaypointsCache.WaypointsDisplayed.Add(wpt); WaypointsCache.isDirty = true; Project.drawWaypoints = true; m_wpt = wpt; // in case the caller needs it m_cameraManager.MarkLocation(location, 0); m_cameraManager.PictureManager.LayersManager.ShowWaypoints = true; m_cameraManager.ProcessCameraMove(); this.Close(); } catch { elevLabel.ForeColor = Color.Red; allcool = false; } } }
public static City parseCityString(string cityStr) { if(!cityStr.StartsWith("REC:")) { return null; } cityStr = cityStr.Substring(4); String name = ""; String country = "US"; String state = ""; String county = ""; String latt = ""; String longt = ""; int importance = 0; String dsg = null; char[] splitter = { '|' }; string[] st = cityStr.Split(splitter); int i = 0; foreach(string str in st) { if(!str.StartsWith("//")) { // we can comment out lines in the box using // System.Console.WriteLine("ZIP info=" + str); switch(i) { case 0: county = "zipcode " + str; break; case 1: name = str; break; case 2: state = str; break; case 3: longt = str; break; case 4: latt = str; break; default: break; } } i++; } /* System.Console.WriteLine("name=\"" + name + "\""); System.Console.WriteLine("country=\"" + country + "\""); System.Console.WriteLine("state=\"" + state + "\""); System.Console.WriteLine("county=\"" + county + "\""); System.Console.WriteLine("latt=\"" + latt + "\""); System.Console.WriteLine("longt=\"" + longt + "\""); System.Console.WriteLine("importance=\"" + importance + "\""); System.Console.WriteLine("dsg=\"" + dsg + "\""); */ double dlat = Convert.ToDouble(latt); double dlong = Convert.ToDouble(longt); GeoCoord loc = new GeoCoord(dlong, dlat); //System.Console.WriteLine(name + " " + loc.toString() + " pop=" + (int)a[6]); return new City(name, loc, country, state, county, 0, importance, dsg); }
public void Fill() { m_hasPutOnMap = false; XmlDocument xmlDoc = new XmlDocument(); try { // let's hope it is good XML and we can load it the easy way: xmlDoc.Load(m_fileName); // we want to traverse XmlDocument fast, as tile load operations can be numerous // and come in pack. So we avoid using XPath and rely mostly on "foreach child": foreach (XmlNode nnode in xmlDoc.ChildNodes) { if (nnode.Name.Equals("features")) { foreach (XmlNode node in nnode) { try { string type = node.Name; if (type.Equals("name")) { Place place = new Place(node); if (place.Importance > 0 && !place.Name.Equals("NAME NOT KNOWN")) { // if(checkForDuplicates) { bool found = false; foreach (LiveObject lo in m_list) { if (lo.GetType().Equals(place.GetType())) { Place p = (Place)lo; if (p.sameAs(place)) { found = true; //LibSys.StatusBar.Trace("duplicate PLACE: " + place + " to " + p); break; } } } if (!found) { m_list.Add(place); namesCount++; } // } else { // checkForDuplicates // m_list.Add(place); // namesCount++; // } } } else if (type.Equals("ppl")) { City city = new City(node); if (checkForDuplicates) { bool found = false; foreach (LiveObject lo in m_list) { if (lo.GetType().Equals(city.GetType())) { City c = (City)lo; if (c.sameAs(city)) { found = true; break; } } } if (!found) { m_list.Add(city); citiesCount++; } } else { m_list.Add(city); citiesCount++; } } } catch (Exception ee) { // bad node, no big deal. Just continue. LibSys.StatusBar.Error("Features:Fill() bad node: " + ee.Message); } } } } } catch (Exception e) { // bad XML. Try to load it the old way. #if DEBUG LibSys.StatusBar.Trace("Warning: Features:Fill(): " + m_fileName + " - bad XML. Loading old style"); #endif StreamReader stream = null; try { stream = new StreamReader(m_fileName); bool isXml = false; int m_lineno = 0; string str; string name = null; string sLat = null; string sLong = null; GeoCoord loc = null; string country = null; string state = null; string county = null; int population = 0; int importance = 0; string dsg = null; bool doCleanup = false; bool inPpl = false; bool inName = false; while ((str = stream.ReadLine()) != null) { m_lineno++; if (m_lineno < 3 && str.StartsWith("<?xml")) { isXml = true; } if (isXml) { // this data formatted in XML comes from NIMA populated_places, converted through a database: try { int slen = str.Length; if (str.StartsWith("<ppl>")) { inPpl = true; doCleanup = true; } else if (str.StartsWith("<name>")) { inName = true; doCleanup = true; } if (doCleanup) { name = null; sLat = null; sLong = null; loc = null; country = null; state = null; county = null; population = 0; importance = 0; dsg = null; doCleanup = false; continue; } if (inPpl) { if (str.StartsWith("</ppl>")) { if (name != null) { // this is the last token, we have all info to list the city: City city = new City(name, loc, country, state, county, population, importance, dsg); //LibSys.StatusBar.Trace("" + m_lineno + " CITY: " + city.toTableString()); if (checkForDuplicates) { bool found = false; foreach (LiveObject lo in m_list) { if (lo.GetType().Equals(city.GetType())) { City c = (City)lo; if (c.sameAs(city)) { found = true; break; } } } if (!found) { m_list.Add(city); citiesCount++; } } else { m_list.Add(city); citiesCount++; } } inPpl = false; continue; } if (str.StartsWith("<p4>")) { sLat = str.Substring(4, slen - 9); } else if (str.StartsWith("<p5>")) { sLong = str.Substring(4, slen - 9); double latitude = Convert.ToDouble(sLat); double longitude = Convert.ToDouble(sLong); loc = new GeoCoord(longitude, latitude); } else if (str.StartsWith("<p12>")) { string tmpDsg = str.Substring(5, slen - 11); if (tmpDsg != null && (tmpDsg.Equals("C") || tmpDsg.Equals("A"))) { dsg = tmpDsg; } } else if (str.StartsWith("<p13>")) { importance = Convert.ToInt32(str.Substring(5, slen - 11)); } else if (str.StartsWith("<p14>")) { country = str.Substring(5, slen - 11); } else if (str.StartsWith("<p15>")) { state = str.Substring(5, slen - 11); } else if (str.StartsWith("<p16>")) { county = str.Substring(5, slen - 11); } else if (str.StartsWith("<p17>")) { int ppos = str.IndexOf("</p17>"); population = Convert.ToInt32(str.Substring(5, ppos - 5)); } else if (str.StartsWith("<p25>")) { name = str.Substring(5, slen - 11); } } if (inName) { if (str.StartsWith("</name>")) { if (name != null && dsg != null && loc != null) { // this is the last token, we have all info to list the place: // adjust importance here: if (dsg.Equals("SEA") || dsg.Equals("OCN")) { // seas and oceans importance = 1; // } else if(dsg.Equals("ADM1")) { // // importance = 2; } else if (dsg.Equals("ISLS") || dsg.Equals("ADM1")) { // importance = 3; // } else if() { // // importance = 4; } else if (dsg.Equals("ISL") || dsg.Equals("PEN") // || dsg.Equals("ADM4") || dsg.Equals("ADM3") || dsg.Equals("ADM2") || dsg.Equals("LK") || dsg.Equals("LKS")) { // importance = 5; } if (importance > 0 && !name.Equals("NAME NOT KNOWN")) { Place place = new Place(name, loc, importance, dsg); //LibSys.StatusBar.Trace("" + m_lineno + " PLACE: " + place.toTableString()); // if(checkForDuplicates) { bool found = false; foreach (LiveObject lo in m_list) { if (lo.GetType().Equals(place.GetType())) { Place p = (Place)lo; if (p.sameAs(place)) { found = true; // LibSys.StatusBar.Trace("duplicate PLACE: " + place + " to " + p); break; } } } if (!found) { m_list.Add(place); namesCount++; } // } else { // checkForDuplicates // m_list.Add(place); // namesCount++; // } } //else //{ // LibSys.StatusBar.Trace("" + m_lineno + " ignored PLACE: " + name + " " + loc + " dsg=" + dsg + " imp=" + importance); //} } inName = false; continue; } if (str.StartsWith("<p4>")) { sLat = str.Substring(4, slen - 9); //LibSys.StatusBar.Trace("line " + m_lineno + " of " + m_fileName + " sLat=" + sLat); } else if (str.StartsWith("<p5>")) { sLong = str.Substring(4, slen - 9); //LibSys.StatusBar.Trace("line " + m_lineno + " of " + m_fileName + " sLong=" + sLong); double latitude = Convert.ToDouble(sLat); double longitude = Convert.ToDouble(sLong); loc = new GeoCoord(longitude, latitude); } else if (str.StartsWith("<p12>")) { dsg = str.Substring(5, slen - 11); } else if (str.StartsWith("<p13>")) { importance = Convert.ToInt32(str.Substring(5)); } else if (str.StartsWith("<p25>")) { name = str.Substring(5, slen - 11); } } } catch (Exception eee) { LibSys.StatusBar.Trace("line " + m_lineno + " of " + m_fileName + " " + eee.Message); //is.close(); } } else { try { City city = parseCityString(str); // LibSys.StatusBar.Trace("CITY: " + city.toTableString()); if (checkForDuplicates) { bool found = false; foreach (LiveObject lo in m_list) { if (lo.GetType().Equals(city.GetType())) { City c = (City)lo; if (c.sameAs(city)) { found = true; break; } } } if (!found) { m_list.Add(city); citiesCount++; } } else { m_list.Add(city); citiesCount++; } } catch (Exception eee) { LibSys.StatusBar.Trace("line " + m_lineno + " of " + m_fileName + " " + eee.Message); } } } } catch (Exception ee) { LibSys.StatusBar.Error("Features:Fill(): " + ee.Message); IsEmpty = true; } finally { if (stream != null) { stream.Close(); } } } m_hasLoaded = true; #if DEBUG LibSys.StatusBar.Trace("OK: Features:Fill(): " + m_baseName + " cities=" + citiesCount + " names=" + namesCount); #endif }
public static void pushBoundaries(GeoCoord loc) { if(loc.Lat > m_topLeft.Lat) { m_topLeft.Lat = loc.Lat; } if(loc.Lat < m_bottomRight.Lat) { m_bottomRight.Lat = loc.Lat; } if(loc.Lng < m_topLeft.Lng) { m_topLeft.Lng = loc.Lng; } if(loc.Lng > m_bottomRight.Lng) { m_bottomRight.Lng = loc.Lng; } }
// scaleIndex 0-24 from m_scales[] public bool ReTileSpecial(int scaleIndex, out int total, out int toLoad, out GeoCoord topLeft, out GeoCoord bottomRight) { topLeft = null; bottomRight = null; // first check if requested scale is supported for this type of map if(m_isSecond || !calcScale(scaleIndex)) { total = 0; toLoad = 0; return false; } if(!m_retilingSpecial && Project.camTrackOn) { firstSuperframe = true; } m_retilingSpecial = true; m_cameraManager.logCamtrackFrame(); // ok, we have a fair chance of rendering the map at the requested scale. base.CameraMoved(); // provoke recalc ReTile(scaleIndex); m_pictureManager.ProcessCameraMove(); // need to call all layers here setMainFormText(); total = m_hCount * m_vCount; // count tiles that have images and need not be downloaded: int _toLoad = total; for(int hhh=0; hhh < m_hCount ;hhh++) { for(int vvv=0; vvv < m_vCount ;vvv++) { TileTerra tile = m_tiles[vvv, hhh]; if(tile != null && tile.backdrop != null && tile.backdrop.HasImage) { _toLoad--; } } } toLoad = _toLoad; topLeft = new GeoCoord(m_cameraManager.CoverageTopLeft); bottomRight = new GeoCoord(m_cameraManager.CoverageBottomRight); return true; }
public Distance distanceFrom(GeoCoord from) { return(m_location.distanceFrom(from)); }
public GeoCoord toGeoLocation(Point point, bool isPrint) { GeoCoord ret = new GeoCoord(0.0d, 0.0d); double pX, pY; if(isPrint) { double offsetX = m_offsetXPrint / m_ratioXPrint; double offsetY = m_offsetYPrint / m_ratioYPrint; // this would be pixel screen coord if there were no scaling: pX = point.X / m_ratioXPrint - offsetX; // tile pixels before scaling pY = - point.Y / m_ratioYPrint + offsetY + 200; } else { double offsetX = m_offsetX / m_ratioX; // tile pixels before scaling double offsetY = m_offsetY / m_ratioY; // this would be pixel screen coord if there were no scaling: pX = point.X / m_ratioX - offsetX; // tile pixels before scaling pY = - point.Y / m_ratioY + offsetY + 200; } // now calculate it in meters and offset the screen UTM pX = pX * m_metersPerPixel + screenUtmX; pY = pY * m_metersPerPixel + screenUtmY; UtmPt utmpt = new UtmPt(); utmpt.X = pX; utmpt.Y = pY; utmpt.Zone = screenUtmZone; LonLatPt lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); ret.Lat = lonlat.Lat; ret.Lng = lonlat.Lon; return ret; }
public GeoCoord add(GeoCoord a) { return new GeoCoord(m_X + a.x(), m_Y + a.y(), m_H + a.h()); }
public Point toScreenPoint(GeoCoord loc, bool isPrint) { Point ret = new Point(); LonLatPt lonlat = new LonLatPt(); lonlat.Lat = loc.Lat; lonlat.Lon = loc.Lng; UtmPt utmpt = Projection.LonLatPtToUtmNad83Pt(lonlat); // calculate where the point would be before the tiles are scaled to the screen: double pX = (utmpt.X - screenUtmX) / m_metersPerPixel; // in pixels double pY = (screenUtmY - utmpt.Y) / m_metersPerPixel; // now scale it to the screen: if(isPrint) { double offsetX = m_offsetXPrint / m_ratioXPrint; double offsetY = m_offsetYPrint / m_ratioYPrint; pX += offsetX; pY += offsetY + 200; // and scale it back: pX *= m_ratioXPrint; pY *= m_ratioYPrint; } else { double offsetX = m_offsetX / m_ratioX; double offsetY = m_offsetY / m_ratioY; pX += offsetX; pY += offsetY + 200; // and scale it back: pX *= m_ratioX; pY *= m_ratioY; } ret.X = (int)pX; ret.Y = (int)pY; return ret; }
public Distance distanceFrom(GeoCoord from) { /* old version: double x = this.subtract(from, false).x(); double y = this.subtract(from, false).y(); // a grad square is cos(latitude) thinner, we need latitude in radians: double midLatRad = (this.add(from).y() / 2.0d) * Math.PI / 180.0d; double latitudeFactor = Math.Cos(midLatRad); double xMeters = Math.Abs(Distance.METERS_PER_DEGREE * x * latitudeFactor); double yMeters = Math.Abs(Distance.METERS_PER_DEGREE * y); Distance distance = new Distance(Math.Sqrt(xMeters*xMeters + yMeters*yMeters)); */ /* // see http://www.malaysiagis.com/related_technologies/gps/article3.cfm for the formula and some code // see http://www.fcaglp.unlp.edu.ar/~esuarez/gmt/1997/0148.html for more double Lon1 = this.Lng; double Lon2 = from.Lng; double Lat1 = this.Lat; double Lat2 = from.Lat; double rad_dist = Math.Acos(Math.Sin(Lat1) * Math.Sin(Lat2) + Math.Cos(Lat1) * Math.Cos(Lat2) * Math.Cos(Lon1 - Lon2)); // to convert from radians to nautical miles, use the formula NM = rad_dist × 3437.7387. Then you can convert to land miles or kilometers. //double meters = rad_dist * rEarth; //3437.7387d * Distance.METERS_PER_NAUTICAL_MILE; */ /* double p1 = Math.Cos(Lat) * Math.Cos(Lng) * Math.Cos(from.Lat) * Math.Cos(from.Lng); double p2 = Math.Cos(Lat) * Math.Sin(Lng) * Math.Cos(from.Lat) * Math.Sin(from.Lng); double p3 = Math.Sin(Lat) * Math.Sin(from.Lat); double rad_dist = Math.Acos(p1 + p2 + p3); */ /* double lon1 = this.Lng; double lon2 = from.Lng; double lat1 = this.Lat; double lat2 = from.Lat; double dlon = (lon2 - lon1); double dlat = (lat2 - lat1); double a = (Math.Sin(dlat/2))*(Math.Sin(dlat/2)) + (Math.Cos(lat1) * Math.Cos(lat2) * (Math.Sin(dlon/2))) * (Math.Cos(lat1) * Math.Cos(lat2) * (Math.Sin(dlon/2))); double rad_dist = 2 * Math.Asin(Math.Min(1.0,Math.Sqrt(a))); */ /* // from http://www.irbs.com/lists/navigation/0111/0022.html // The haversine distance formula goes as follows: double lon1 = this.Lng; double lon2 = from.Lng; double lat1 = this.Lat; double lat2 = from.Lat; double DLat = lat2 - lat1; double DLo = lon2 - lon1; double p1 = Math.Sin(DLat/2); double p2 = Math.Sin(DLo/2); double A = p1 * p1 + Math.Cos(lat2) * Math.Cos(lat1) * p2 * p2; double meters = EARTH_RADIUS * Math.Asin (Math.Sqrt(A)); */ // from http://www.movable-type.co.uk/scripts/LatLong.html double lon1 = this.Lng * Math.PI / 180.0d; double lon2 = from.Lng * Math.PI / 180.0d; double lat1 = this.Lat * Math.PI / 180.0d; double lat2 = from.Lat * Math.PI / 180.0d; double dLat = lat2 - lat1; double dLong = lon2 - lon1; double a = Math.Sin(dLat/2) * Math.Sin(dLat/2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Sin(dLong/2) * Math.Sin(dLong/2); double c = 2.0d * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0d - a)); double meters = EARTH_RADIUS * c; Distance distance = new Distance(meters); return distance; }
internal static int getZone(GeoCoord loc) { LonLatPt lonlat = new LonLatPt(); lonlat.Lat = loc.Lat; lonlat.Lon = loc.Lng; int zone = Projection.LonLatPtToZone(lonlat); return zone; }
protected void queryDisconnected() { GeoCoord covTL = m_cameraManager.CoverageTopLeft; GeoCoord covBR = m_cameraManager.CoverageBottomRight; double marginY = m_retilingSpecial ? 0.0d : ((covBR.Lng - covTL.Lng) / 40.0d); double marginX = m_retilingSpecial ? 0.0d : ((covTL.Lat - covBR.Lat) / 40.0d * m_cameraManager.xScaleFactor); double covTL_Lng = covTL.Lng - marginX; double covTL_Lat = covTL.Lat + marginY; double covBR_Lng = covBR.Lng + marginX; double covBR_Lat = covBR.Lat - marginY; int currentZone = getZone(m_cameraManager.Location); LonLatPt lonlat = new LonLatPt(); lonlat.Lat = covTL_Lat; lonlat.Lon = covTL_Lng; UtmPt utmptTL = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone lonlat.Lat = covBR_Lat; lonlat.Lon = covBR_Lng; UtmPt utmptBR = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone if(utmptTL.Zone != currentZone) { lonlat.Lat = m_cameraManager.Location.Lat; lonlat.Lon = m_cameraManager.Location.Lng; UtmPt utmptCam = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone double dX = utmptBR.X - utmptCam.X; utmptTL.X = utmptCam.X - dX; utmptTL.Zone = currentZone; } else if(utmptBR.Zone != currentZone) { lonlat.Lat = m_cameraManager.Location.Lat; lonlat.Lon = m_cameraManager.Location.Lng; UtmPt utmptCam = Projection.LonLatPtToUtmNad83Pt(lonlat); // can be in other than currentZone double dX = utmptCam.X - utmptTL.X; utmptBR.X = utmptCam.X + dX; utmptBR.Zone = currentZone; } int iScale = (int)m_tileScale; int metersPerPixel = (1 << ((int) iScale - 10)); int factor = 200 * metersPerPixel; if(!firstSuperframe || xEnd - xStart == 0 || m_lastFactor == 0) { xStart = (int)Math.Floor(utmptTL.X / factor); yStart = (int)Math.Ceiling(utmptTL.Y / factor); xEnd = (int)Math.Ceiling(utmptBR.X / factor); yEnd = (int)Math.Floor(utmptBR.Y / factor); m_lastFactor = factor; } else { xStart = xStart * m_lastFactor / factor; yStart = yStart * m_lastFactor / factor; xEnd = xEnd * m_lastFactor / factor; yEnd = yEnd * m_lastFactor / factor; firstSuperframe = false; } int numTilesX = xEnd - xStart; int numTilesY = yStart - yEnd; // we need to remember UTM coordinates for Projection operation: m_scale = m_tileScale; m_metersPerPixel = (1 << ((Int32) m_scale - 10)); screenUtmZone = currentZone; screenUtmX = xStart * factor; screenUtmY = (yStart - 1) * factor; cleanTiles(); // dispose of previous tile array, if any m_hCount = numTilesX; m_vCount = numTilesY; UtmPt utmpt = new UtmPt(); utmpt.X = xStart * factor; utmpt.Y = yStart * factor; utmpt.Zone = currentZone; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double topLeftLat = lonlat.Lat; double topLeftLng = lonlat.Lon; utmpt.X = (xStart + numTilesX) * factor; utmpt.Y = (yStart - numTilesY) * factor; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double bottomRightLat = lonlat.Lat; double bottomRightLng = lonlat.Lon; m_tileResolutionDegreesH = Math.Abs(bottomRightLng - topLeftLng) / m_hCount; m_tileResolutionDegreesV = Math.Abs(bottomRightLat - topLeftLat) / m_vCount; #if DEBUG LibSys.StatusBar.Trace("m_tileResolutionDegreesH=" + m_tileResolutionDegreesH + " m_tileResolutionDegreesV=" + m_tileResolutionDegreesV); #endif int themeCode = getThemeCode(); lock(tilesLock) { m_tiles = new TileTerra[m_vCount, m_hCount]; SnapList snapLat = new SnapList(m_tileResolutionDegreesV, true); SnapList snapLng = new SnapList(m_tileResolutionDegreesH, true); int xx = (int)xStart; for(int hhh=0; hhh < m_hCount ;hhh++) { int yy = (int)yStart; for(int vvv=0; vvv < m_vCount ;vvv++) { utmpt.X = xx * factor; utmpt.Y = (yy) * factor; utmpt.Zone = currentZone; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double tllat = lonlat.Lat; double tllng = lonlat.Lon; utmpt.X = (xx + 1) * factor; utmpt.Y = (yy - 1) * factor; lonlat = Projection.UtmNad83PtToLonLatPt(utmpt); double brlat = lonlat.Lat; double brlng = lonlat.Lon; GeoCoord tileTopLeft = new GeoCoord(tllng, tllat); GeoCoord tileBottomRight = new GeoCoord(brlng, brlat); String baseName = String.Format("T{0}-S{1}-Z{2}-X{3}-Y{4}", themeCode, (Int32)m_tileScale, currentZone, xx, (yy - 1)); //String baseName = "T" + themeCode + "-S" + (Int32)m_tileScale + "-Z" + currentZone + "-X" + xx + "-Y" + (yy - 1); if(!m_retilingSpecial) { // adding to snap lists prepares them for calculating snap points: snapLat.Add(tllat); snapLat.Add(brlat); snapLng.Add(tllng); snapLng.Add(brlng); } m_tiles[vvv, hhh] = new TileTerra(this, m_tileScale, tileTopLeft, tileBottomRight); m_tiles[vvv, hhh].baseName = baseName; m_tiles[vvv, hhh].init(); // gets backdrop, or starts the process of loading backdrop #if DEBUG //LibSys.StatusBar.Trace("[" + vvv + "," + hhh + "] " + baseName); //LibSys.StatusBar.Trace(" -- topLeft=" + tileTopLeft + " bottomRight=" + tileBottomRight); #endif yy--; } xx++; } // snap to the grid. If special retiling, distortion is ok: for(int vvv=0; !m_retilingSpecial && vvv < m_vCount ;vvv++) { for(int hhh=0; hhh < m_hCount ;hhh++) { TileTerra tile = m_tiles[vvv, hhh]; // snap the tile's corners to grid: tile.getBottomRight().X = snapLng.snap(tile.getBottomRight().X); tile.getBottomRight().Y = snapLat.snap(tile.getBottomRight().Y); tile.getTopLeft().X = snapLng.snap(tile.getTopLeft().X); tile.getTopLeft().Y = snapLat.snap(tile.getTopLeft().Y); } } // we need topleft tile for Projection: m_topLeftTile = m_tiles[0, 0]; calcRatios(); // compute resolution to display, meters per pixel, with overzoom indicator: double ratio = (m_ratioX + m_ratioY) / 2.0d; string overzoom = ("1m".Equals(m_tileScaleName) && ratio > 1.1d) ? " (overzoom)" : ""; hasRenderedTiles = true; m_placeDescription = "[" + abbMessage + "]"; m_formText = Project.PROGRAM_NAME_HUMAN + " - " + m_placeDescription + " " + m_tileScaleName + "/pixel * " + ratio + overzoom; // + " (" + m_tileScale + ")"; } // end lock #region old code relying on Tiles DB in TerraserverCache /* int iTheme = (int)m_curTheme; string where = "theme = " + iTheme + " AND scale = " + iScale + " AND name LIKE '%-Z" + currentZone + "-%'" + " AND brlng > " + covTL_Lng + " AND tllng <" + covBR_Lng + " AND brlat < " + covTL_Lat + " AND tllat > " + covBR_Lat; #if DEBUG LibSys.StatusBar.Trace("WHERE " + where); #endif // sort by name gives us rows sorted from bottom left up to top left (per line scan) all the way to top right - // like a TV scanning, turned on the left side. The Y coord axis goes up, the X - to the right. string sort = "name"; DataRow[] rows = TerraserverCache.TilesDS.Tables[0].Select(where, sort); // not all tiles may be present in the grid. Restore the grid structure: if(rows != null && rows.Length > 0) { // use the first tile for grid evaluation: int tileScale = (int)rows[0]["scale"]; double tllng = (double)rows[0]["tllng"]; double tllat = (double)rows[0]["tllat"]; double brlng = (double)rows[0]["brlng"]; double brlat = (double)rows[0]["brlat"]; m_tileResolutionDegreesH = Math.Abs(brlng - tllng); m_tileResolutionDegreesV = Math.Abs(brlat - tllat); #if DEBUG LibSys.StatusBar.Trace("tl=" + tllng + "," + tllat + " br=" + brlng + "," + brlat); LibSys.StatusBar.Trace("m_tileResolutionDegreesH=" + m_tileResolutionDegreesH + " m_tileResolutionDegreesV=" + m_tileResolutionDegreesV); LibSys.StatusBar.Trace("tile 0 -- topLeft=" + (new GeoCoord(tllng,tllat)) + " bottomRight=" + (new GeoCoord(brlng,brlat))); #endif // evaluate dimensions of tile matrix and corners of the tile-covered frame: double d; int hCount = 0; for (d=tllng; d > covTL.Lng ;d -= m_tileResolutionDegreesH) { //LibSys.StatusBar.Trace("working left -- topLeft=" + (new GeoCoord(d,tllat))); hCount++; } double topLeftLng = d; for (d=tllng; d < covBR.Lng ;d += m_tileResolutionDegreesH) { //LibSys.StatusBar.Trace("working right -- topLeft=" + (new GeoCoord(d,tllat))); hCount++; } double bottomRightLng = d; int vCount = 0; for (d=tllat; d < covTL.Lat ;d += m_tileResolutionDegreesV) { //LibSys.StatusBar.Trace("working up -- topLeft=" + (new GeoCoord(tllng, d))); vCount++; } double topLeftLat = d; for (d=tllat; d > covBR.Lat ;d -= m_tileResolutionDegreesV) { //LibSys.StatusBar.Trace("working down -- topLeft=" + (new GeoCoord(tllng, d))); vCount++; } double bottomRightLat = d; #if DEBUG LibSys.StatusBar.Trace("hCount=" + hCount + " vCount=" + vCount); LibSys.StatusBar.Trace("topLeft=" + topLeftLng + "," + topLeftLat + " bottomRight=" + bottomRightLng + "," + bottomRightLat); LibSys.StatusBar.Trace("topLeft=" + (new GeoCoord(topLeftLng,topLeftLat)) + " bottomRight=" + (new GeoCoord(bottomRightLng,bottomRightLat))); #endif cleanTiles(); // dispose of previous tile array, if any m_vCount = vCount+2; // make more cells for inperfections in tile corners. m_hCount = hCount+2; // extra tiles will be initialized as "empty". The order of the tiles is random. lock(tilesLock) { m_tiles = new TileTerra[m_vCount, m_hCount]; SnapList snapLat = new SnapList(m_tileResolutionDegreesV, true); SnapList snapLng = new SnapList(m_tileResolutionDegreesH, true); int vv = 0; int hh = 0; int rowCount = 0; foreach(DataRow row in rows) { string basename = (string)row["name"]; tileScale = (int)row["scale"]; tllng = (double)row["tllng"]; tllat = (double)row["tllat"]; brlng = (double)row["brlng"]; brlat = (double)row["brlat"]; // adding to snap lists prepares them for calculating snap points: snapLat.Add(tllat); snapLat.Add(brlat); snapLng.Add(tllng); snapLng.Add(brlng); // find the right position for the tile: // (turns out that order of tiles does not matter) // place the tile: GeoCoord tileTopLeft = new GeoCoord(tllng, tllat, 0.0d); GeoCoord tileBottomRight = new GeoCoord(brlng, brlat, 0.0d); m_tiles[vv, hh] = new TileTerra(this, (Scale)tileScale, tileTopLeft, tileBottomRight); #if DEBUG LibSys.StatusBar.Trace(" ----- tile: " + basename + " --- tl=" + tllng + "," + tllat + " br=" + brlng + "," + brlat); #endif m_tiles[vv, hh].baseName = basename; m_tiles[vv, hh].init(); // gets backdrop, or starts the process of loading backdrop if(++rowCount >= m_hCount * m_vCount) { // no matter what, we don't want to overflow the array and get an exception. Shouldn't happen though. LibSys.StatusBar.Error("too many tiles in rowset"); break; } hh++; if(hh >= m_hCount) { hh = 0; vv++; } // adjust frame corners to eliminate rounding errors, if possible: topLeftLng = Math.Min(topLeftLng, tllng); topLeftLat = Math.Max(topLeftLat, tllat); bottomRightLng = Math.Max(bottomRightLng, brlng); bottomRightLat = Math.Min(bottomRightLat, brlat); //break; } m_cameraManager.terraTopLeft = new GeoCoord(topLeftLng, topLeftLat); m_cameraManager.terraBottomRight = new GeoCoord(bottomRightLng, bottomRightLat); // make sure there are no null tiles in the array: tllng = topLeftLng; tllat = topLeftLat; brlng = tllng + m_tileResolutionDegreesH; brlat = tllat - m_tileResolutionDegreesV; for(int vvv=0; vvv < m_vCount ;vvv++) { for(int hhh=0; hhh < m_hCount ;hhh++) { TileTerra tile = m_tiles[vvv, hhh]; if(tile == null) { GeoCoord tileTopLeft = new GeoCoord(snapLng.snap(tllng), snapLat.snap(tllat), 0.0d); GeoCoord tileBottomRight = new GeoCoord(snapLng.snap(brlng), snapLat.snap(brlat), 0.0d); m_tiles[vvv, hhh] = new TileTerra(this, (Scale)tileScale, tileTopLeft, tileBottomRight); m_tiles[vvv, hhh].baseName = "empty"; tile = m_tiles[vvv, hhh]; //m_tiles[vvv, hhh].init(); // gets backdrop, or starts the process of loading backdrop } else { // snap the tile's corners to grid: tile.getBottomRight().X = snapLng.snap(tile.getBottomRight().X); tile.getBottomRight().Y = snapLat.snap(tile.getBottomRight().Y); tile.getTopLeft().X = snapLng.snap(tile.getTopLeft().X); tile.getTopLeft().Y = snapLat.snap(tile.getTopLeft().Y); } // we need topleft tile for Projection: if(m_topLeftTile == null || tile.getTopLeft().X <= m_topLeftTile.getTopLeft().X && tile.getTopLeft().Y >= m_topLeftTile.getTopLeft().Y) { m_topLeftTile = tile; } tllng += m_tileResolutionDegreesH; brlng += m_tileResolutionDegreesH; } tllat -= m_tileResolutionDegreesV; brlat -= m_tileResolutionDegreesV; } } // end lock // compute parameters for Projection: Rectangle tileRect = m_topLeftTile.getFrameRectangle(); m_ratioX = ((double)tileRect.Width - 1.5d) / 200.0d; // -1.5 corrects added 1 in getFrameRectangle(), and probability of rounding m_ratioY = ((double)tileRect.Height - 1.5d) / 200.0d; m_offsetX = tileRect.X; m_offsetY = tileRect.Y; // compute resolution to display, meters per pixel, with overzoom indicator: double ratio = (m_ratioX + m_ratioY) / 2.0d; string overzoom = ("1m".Equals(m_tileScaleName) && ratio > 1.1d) ? " (overzoom)" : ""; try { // compute UTMP reference values for Projection operation: screenUtmZone = currentZone; m_scale = (Scale)m_tileScale; m_metersPerPixel = (1 << ((Int32) m_scale - 10)); // we have to parse tile name here - something like T1-S16-Z17-X57-Y368 char[] sep = new Char[1] { '-' }; string[] split = m_topLeftTile.baseName.Split(sep); int utmX = Convert.ToInt32(split[3].Substring(1)); int utmY = Convert.ToInt32(split[4].Substring(1)); screenUtmX = (utmX * 200 * m_metersPerPixel); screenUtmY = (utmY * 200 * m_metersPerPixel); hasRenderedTiles = true; } catch {} m_placeDescription = "[" + abbMessage + "]"; m_formText = Project.PROGRAM_NAME_HUMAN + " - " + m_placeDescription + " " + m_tileScaleName + "/pixel * " + ratio + overzoom; // + " (" + m_tileScale + ")"; } else { // there are no tiles for this scale, but if we zoomed in the existing tiles may work. Make sure distortion is taken care of. try { // find which tile is now top-left (screen corner contained in this tile): Rectangle tileRect = new Rectangle(0, 0, 0, 0); for(int vvv=0; vvv < m_vCount ;vvv++) { for(int hhh=0; hhh < m_hCount ;hhh++) { TileTerra tile = m_tiles[vvv, hhh]; tileRect = tile.getFrameRectangle(); if(tileRect.Contains(0, 0)) { m_topLeftTile = tile; goto found; } } } goto notFound; found: // compute parameters for Projection: m_ratioX = ((double)tileRect.Width - 1.5d) / 200.0d; // -1.5 corrects added 1 in getFrameRectangle(), and probability of rounding m_ratioY = ((double)tileRect.Height - 1.5d) / 200.0d; m_offsetX = tileRect.X; m_offsetY = tileRect.Y; // compute resolution to display, meters per pixel, with overzoom indicator: double ratio = (m_ratioX + m_ratioY) / 2.0d; string overzoom = " (overzoom)"; // compute UTMP reference values for Projection operation: screenUtmZone = currentZone; m_metersPerPixel = (1 << ((Int32) m_scale - 10)); // we have to parse tile name here - something like T1-S16-Z17-X57-Y368 char[] sep = new Char[1] { '-' }; string[] split = m_topLeftTile.baseName.Split(sep); m_tileScale = (Scale)Convert.ToInt32(split[1].Substring(1)); m_scale = (Scale)m_tileScale; m_tileScaleName = scaleName(m_scale); int utmX = Convert.ToInt32(split[3].Substring(1)); int utmY = Convert.ToInt32(split[4].Substring(1)); screenUtmX = (utmX * 200 * m_metersPerPixel); screenUtmY = (utmY * 200 * m_metersPerPixel); hasRenderedTiles = true; m_placeDescription = "[" + abbMessage + "]"; m_formText = Project.PROGRAM_NAME_HUMAN + " - " + m_placeDescription + " " + m_tileScaleName + "/pixel * " + ratio + overzoom; // + " (" + m_tileScale + ")"; notFound: ; } catch {} } */ #endregion // Landmarks array was cleaned in the beginning of ReTile(). // now fill the landmarks from the database: string where = "lng > " + covTL_Lng + " AND lng <" + covBR_Lng + " AND lat < " + covTL_Lat + " AND lat > " + covBR_Lat; DataRow[] rows = TerraserverCache.LandmarksDS.Tables["lm"].Select(where); if(rows != null && rows.Length > 0) { int numLandmarks = rows.Length; if(numLandmarks > 0) { foreach(DataRow row in rows) { string name = (string)row["name"]; string type = (string)row["type"]; double lat = (double)row["lat"]; double lng = (double)row["lng"]; Landmark lm = new Landmark(name, new GeoCoord(lng, lat, 0.0d), type); TerraserverCache.AddLandmark(lm); } } } }
public static Waypoint createPhotoTrackpoint(PhotoDescr photoDescr, TimeSpan photoTimeShift, int tzId) { if(photoDescr.hasCoordinates) { // There is EXIF coordinates set, use it. GeoCoord loc = new GeoCoord(photoDescr.Longitude, photoDescr.Latitude, photoDescr.Altitude); string name = photoDescr.imageName; string source = photoDescr.imageSource; string url = photoDescr.imageUrl; Waypoint wpt0 = new Waypoint(loc, Project.localToZulu(photoDescr.DTOrig), LiveObjectTypes.LiveObjectTypeWaypoint, -1, name, source, url) ; wpt0.Desc = photoDescr.imageName; wpt0.ThumbImage = photoDescr.ThumbnailImage; wpt0.ThumbSource = photoDescr.imageThumbSource; wpt0.ThumbPosition = Project.thumbPosition; wpt0.imageWidth = photoDescr.Width; wpt0.imageHeight = photoDescr.Height; wpt0.PhotoTimeShift = new TimeSpan(0L); // we need to shift the timestamp a bit if the spot is taken: while(WaypointsWithThumbs.ContainsKey(wpt0.DateTime)) { DateTime tmp = wpt0.DateTime; wpt0.DateTime = tmp.AddMilliseconds(1); } // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt0.DateTime, wpt0); CurrentWptIndex = WaypointsWithThumbs.Count - 1; WaypointsCache.addWaypoint(wpt0); return wpt0; } if(photoDescr.DTOrig.Equals(DateTime.MinValue)) { // try to get it from file name: photoDescr.ensureImageExists(); Waypoint wpt0 = WaypointsCache.getWaypointByName(photoDescr.imageName); if(wpt0 != null) { //wpt0.Desc = photoDescr.imageName; wpt0.ThumbImage = photoDescr.ThumbnailImage; wpt0.ThumbSource = photoDescr.imageThumbSource; wpt0.ThumbPosition = Project.thumbPosition; wpt0.imageWidth = photoDescr.Width; wpt0.imageHeight = photoDescr.Height; wpt0.PhotoTimeShift = new TimeSpan(0L); // we need to shift the timestamp a bit if the spot is taken: while(WaypointsWithThumbs.ContainsKey(wpt0.DateTime)) { DateTime tmp = wpt0.DateTime; wpt0.DateTime = tmp.AddMilliseconds(1); } // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt0.DateTime, wpt0); CurrentWptIndex = WaypointsWithThumbs.Count - 1; return wpt0; } else { registerUnrelatedPhoto(photoDescr); } return null; } TimeSpan timeZoneSpan = MyTimeZone.timeSpanById(tzId); DateTime timeStamp = Project.localToZulu(photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan); //LibSys.StatusBar.Trace("adjusted zulu time=" + timeStamp); registerImageTimestamp(timeStamp); if(photoDescr.imageSourceIsLocal && photoDescr.image == null) { // try to get it from file name: photoDescr.ensureImageExists(); registerUnrelatedPhoto(photoDescr); return null; } Waypoint wpt = null; Waypoint wpt1; Waypoint wpt2; // wpt2 is hit if exact match on the timestamp; wpt1 may turn null, but not wpt2. if(WaypointsCache.trackpointByTime(timeStamp, out wpt1, out wpt2)) { // create duplicate waypoint and add it to the same track - to hold the image wpt = new Waypoint(wpt2); if(wpt1 == null) { // exact match on wpt2 } else { // somewhere between wpt1 and wpt2 double dt = (wpt2.DateTime - wpt1.DateTime).Ticks; double dt1 = (timeStamp - wpt1.DateTime).Ticks; if(dt > 0) { double ratio = dt1 / dt; wpt.Location.Lat = wpt1.Location.Lat + (wpt2.Location.Lat - wpt1.Location.Lat) * ratio; wpt.Location.Lng = wpt1.Location.Lng + (wpt2.Location.Lng - wpt1.Location.Lng) * ratio; } } wpt.DateTime = timeStamp; wpt.Desc = photoDescr.imageName; Track trk = WaypointsCache.getTrackById(wpt.TrackId); // we need to shift the timestamp a bit if the spot is taken: while(WaypointsWithThumbs.ContainsKey(wpt.DateTime) || trk.Trackpoints.ContainsKey(wpt.DateTime)) { DateTime tmp = wpt.DateTime; wpt.DateTime = tmp.AddMilliseconds(1); } trk.insertWaypoint(wpt); wpt.ThumbImage = photoDescr.ThumbnailImage; wpt.ThumbSource = photoDescr.imageThumbSource; wpt.ThumbPosition = Project.thumbPosition; wpt.imageWidth = photoDescr.Width; wpt.imageHeight = photoDescr.Height; wpt.PhotoTimeShift = photoTimeShift; // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt.DateTime, wpt); CurrentWptIndex = WaypointsWithThumbs.Count - 1; } else { registerUnrelatedPhoto(photoDescr); } return wpt; }
public DlgMakeWaypoint(CameraManager cameraManager, Point clickPoint) : this(cameraManager) { m_clickPoint = clickPoint; m_clickLocation = m_cameraManager.toGeoLocation(m_clickPoint); setCoordFields(m_clickLocation); Project.setDlgIcon(this); waypointNameTextBox.Focus(); }
private bool m_triedReload = false; // limits reload attempts #endregion Fields #region Constructors public Tile(TileSet ts, string tileScale, GeoCoord topLeft, GeoCoord bottomRight) { m_tileSet = ts; m_tileScale = tileScale; m_topLeft = topLeft.Clone(); m_bottomRight = bottomRight.Clone(); #if DEBUG LibSys.StatusBar.Trace("Tile() topLeft=" + m_topLeft.ToString() + " bottomRight=" + m_bottomRight.ToString()); #endif }
private void estimateOrAct(bool doAct, bool doDraw) { if(!m_loaded || m_working) { return; } estimateLabel.Text = "estimating download... please wait ..."; estimateLabel.Refresh(); Application.DoEvents(); Graphics graphics = PictureManager.This.Graphics; Cursor.Current = Cursors.WaitCursor; double spreadMeters = m_spread * Distance.METERS_PER_MILE; double spreadDegrees = spreadMeters / Distance.METERS_PER_DEGREE; int scaleIndex = 10 + m_preloadScale; if(!doAct) { m_listOfTiles.Clear(); } for(int i=0; i < m_trk.Trackpoints.Count-1 ;i++) { Waypoint trkpt1 = (Waypoint)m_trk.Trackpoints.GetByIndex(i); Waypoint trkpt2 = (Waypoint)m_trk.Trackpoints.GetByIndex(i+1); Distance d = trkpt2.Location.distanceFrom(trkpt1.Location); int steps = (int)Math.Ceiling(d.Meters / spreadMeters * 2); double stepLng = (trkpt2.Location.Lng - trkpt1.Location.Lng) / steps; double stepLat = (trkpt2.Location.Lat - trkpt1.Location.Lat) / steps; GeoCoord center = new GeoCoord(trkpt1.Location.Lng, trkpt1.Location.Lat); for(int j=0; j < steps ;j++) { GeoCoord topLeft = new GeoCoord(center.Lng - spreadDegrees, center.Lat + spreadDegrees); GeoCoord bottomRight = new GeoCoord(center.Lng + spreadDegrees, center.Lat - spreadDegrees); if(doAct) { TileSetTerraLayout.downloadThemesAtLevel(topLeft, bottomRight, scaleIndex, scaleUpCheckBox.Checked, m_doAerial, m_doColor, m_doTopo); } else { TileSetTerraLayout.listTilesAtLevelsWithType(m_listOfTiles, topLeft, bottomRight, scaleIndex, scaleUpCheckBox.Checked, m_doAerial, m_doColor, m_doTopo); } if(doDraw) { CameraManager.This.PaintGeoRect(topLeft, bottomRight, graphics, Pens.Red, null); // Brush brush = new SolidBrush(Color.FromArgb(10, 255, 0, 0)); // CameraManager.This.HighlightGeoRect(topLeft, bottomRight, graphics, brush); } center.Lng += stepLng; center.Lat += stepLat; Application.DoEvents(); } } if(doAct) { estimateLabel.Text = "You can close this dialog now and do other things,\r\nincluding preload along another route.\r\nDownload will continue, watch the green button at the bottom of the screen."; } else { // try to come up with some numbers here: int factor = 0; double mbFactor = 0; if(m_doAerial) { factor++; mbFactor += 10.0d; } if(m_doColor) { factor++; mbFactor += 15.0d; } if(m_doTopo) { factor++; mbFactor += 10.0d; } mbFactor /= factor; int toCover = m_listOfTiles.Count; int toLoad = toCover; // no way to know which are loaded int toLoadMb = (int)Math.Round(m_listOfTiles.Count * mbFactor / 1000.0d); estimateLabel.Text = "tiles cache: " + Project.GetTerraserverMapsBasePath() + "\r\ntiles along the route: " + toCover + (toLoadMb > 0 ? " - approximately " + toLoadMb + " Mb" : ""); // Estimate exported size: int toLoadMbExport = toLoadMb; double tileSize = 41.5d; double aerialTileSize = Project.pdaExportUseWebsafeGrayscalePalette ? 40.1d : 19.6d; double aerialShare = m_doAerial ? (1.0d / factor) : 0.0d; double nonAerialShare = 1.0d - aerialShare; switch(Project.pdaExportImageFormat) { case 0: // bmp websafe case 1: // bmp optimized toLoadMbExport = (int)Math.Round(m_listOfTiles.Count * (tileSize * nonAerialShare + aerialTileSize * aerialShare) / 1000.0d); break; case 2: // jpeg break; } estimateLabel.Text += "\r\nPDA export size: " + toLoadMbExport + " Mb - to folder: " + Project.exportDestFolder; } // wrap-up and return: Cursor.Current = Cursors.Default; if(doAct) { closeButton.Text = "Close"; } LibSys.StatusBar.Trace("Preload along route: working..."); }
public bool insideCurrentZone(GeoCoord loc) { return getZone(loc) == screenUtmZone; }