Example #1
0
 public static Framework.Data.Location GetLocationOfAddress(string address)
 {
     Framework.Data.Location result = null;
     try
     {
         string s = null;
         HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", HttpUtility.UrlEncode(address)));
         wr.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
         wr.Method = WebRequestMethods.Http.Get;
         using (HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse())
         {
             using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
             {
                 s = reader.ReadToEnd();
                 webResponse.Close();
             }
         }
         if (s != null && s.Length > 0)
         {
             XmlDocument xdoc = new XmlDocument();
             xdoc.LoadXml(s);
             XmlNode n = xdoc.SelectSingleNode("GeocodeResponse/result/geometry/location");
             result = new Framework.Data.Location();
             result.SetLocation(Conversion.StringToDouble(n.SelectSingleNode("lat").InnerText), Conversion.StringToDouble(n.SelectSingleNode("lng").InnerText));
         }
     }
     catch
     {
         result = null;
     }
     return result;
 }
Example #2
0
 private void buttonWithinRadius_Click(object sender, EventArgs e)
 {
     _withinRadius = true;
     try
     {
         if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
         {
             object o = webBrowser1.Document.InvokeScript("getCenterPosition");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString().Replace("(", "").Replace(")", "");
                 _center = Utils.Conversion.StringToLocation(s);
             }
             else
             {
                 return;
             }
             o = webBrowser1.Document.InvokeScript("getRadius");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString();
                 _radius = Utils.Conversion.StringToDouble(s);
             }
             else
             {
                 return;
             }
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
             Close();
         }
     }
     catch
     {
     }
 }
Example #3
0
        public async override Task <bool> ActionAsync(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_IMPORT)
            {
                if (SiteManager.Instance.CheckAPIAccess())
                {
                    using (ImportByRadiusForm dlg = new ImportByRadiusForm(Core))
                    {
                        if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            _filter    = dlg.Filter;
                            _radiusKm  = dlg.RadiusKm;
                            _centerLoc = dlg.Center;
                            await PerformImport();

                            if (!string.IsNullOrEmpty(_errormessage))
                            {
                                System.Windows.Forms.MessageBox.Show(_errormessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Example #4
0
        public List <Framework.Data.AreaInfo> GetAreasOfLocation(Framework.Data.Location loc)
        {
            List <Framework.Data.AreaInfo> result = new List <Framework.Data.AreaInfo>();

            PreLoadAreaInfo();
            List <Framework.Data.AreaInfo> affectedAreas = (from ai in _cachedAreaInfo
                                                            where ai.MinLat <= loc.Lat && ai.MaxLat >= loc.Lat && ai.MinLon <= loc.Lon && ai.MaxLon >= loc.Lon
                                                            select ai).ToList();

            foreach (Framework.Data.AreaInfo ai in affectedAreas)
            {
                GetPolygonOfArea(ai);
                if (ai.Polygons != null)
                {
                    List <Framework.Data.Polygon> pgs = (from pg in ai.Polygons
                                                         where pg.MinLat <= loc.Lat && pg.MaxLat >= loc.Lat && pg.MinLon <= loc.Lon && pg.MaxLon >= loc.Lon
                                                         select pg).ToList();
                    foreach (Framework.Data.Polygon pg in pgs)
                    {
                        if (Utils.Calculus.PointInPolygon(pg, loc))
                        {
                            result.Add(ai);
                            break;
                        }
                    }
                }
            }
            return(result);
        }
Example #5
0
 private void bnAsCenter_Click(object sender, EventArgs e)
 {
     Framework.Data.Location ll = null;
     if (tbSolutions.SelectionLength > 0)
     {
         ll = Utils.Conversion.StringToLocation(tbSolutions.SelectedText);
     }
     if (ll != null)
     {
         Core.CenterLocation.SetLocation(ll.Lat, ll.Lon);
         Core.Geocaches.BeginUpdate();
         foreach (Framework.Data.Geocache gc in Core.Geocaches)
         {
             Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation);
         }
         Core.Geocaches.EndUpdate();
     }
     else
     {
         MessageBox.Show(
             StrRes.GetString(StrRes.NO_PROPER_COORDINATES_SELECTED),
             "Formula Solver",
             MessageBoxButtons.OK,
             MessageBoxIcon.Information
             );
     }
 }
Example #6
0
 private void buttonWithinRadius_Click(object sender, EventArgs e)
 {
     _withinRadius = true;
     try
     {
         if (_webBrowser.IsReady)
         {
             object o = _webBrowser.InvokeScript("getCenterPosition()");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString().Replace("(", "").Replace(")", "");
                 _center = Utils.Conversion.StringToLocation(s);
             }
             o = _webBrowser.InvokeScript("getRadius()");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString();
                 _radius = Utils.Conversion.StringToDouble(s);
             }
         }
     }
     catch
     {
     }
 }
Example #7
0
        public List <Framework.Data.AreaInfo> GetEnvelopAreasOfLocation(Framework.Data.Location loc, List <Framework.Data.AreaInfo> inAreas)
        {
            List <Framework.Data.AreaInfo> result = new List <Framework.Data.AreaInfo>();

            PreLoadAreaInfo();
            List <Framework.Data.AreaInfo> affectedAreas = (from ai in _cachedAreaInfo
                                                            join b in inAreas on ai equals b
                                                            where ai.MinLat <= loc.Lat && ai.MaxLat >= loc.Lat && ai.MinLon <= loc.Lon && ai.MaxLon >= loc.Lon
                                                            select ai).ToList();

            foreach (Framework.Data.AreaInfo ai in affectedAreas)
            {
                GetPolygonOfArea(ai);
                if (ai.Polygons != null)
                {
                    if ((from pg in ai.Polygons
                         where pg.MinLat <= loc.Lat && pg.MaxLat >= loc.Lat && pg.MinLon <= loc.Lon && pg.MaxLon >= loc.Lon
                         select pg).Count() > 0)
                    {
                        result.Add(ai);
                    }
                }
            }
            return(result);
        }
 private void button1_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     try
     {
         using (Utils.DBCon dbcon = initDatabase())
         {
             Framework.Data.Location l = Utils.Conversion.StringToLocation(textBox1.Text);
             if (l != null && listView1.SelectedItems.Count > 0)
             {
                 Framework.Data.Geocache gc = listView1.SelectedItems[0].Tag as Framework.Data.Geocache;
                 if (dbcon.ExecuteNonQuery(string.Format("update coord set lat={0}, lon={1} where code='{2}'", l.SLat, l.SLon, gc.Code.Replace("'", "''"))) == 0)
                 {
                     dbcon.ExecuteNonQuery(string.Format("insert into coord (lat, lon, code) values ({0}, {1}, '{2}')", l.SLat, l.SLon, gc.Code.Replace("'", "''")));
                 }
                 gc.BeginUpdate();
                 gc.Lat = l.Lat;
                 gc.Lon = l.Lon;
                 gc.EndUpdate();
                 listView1.Items.Remove(listView1.SelectedItems[0]);
             }
         }
     }
     catch
     {
     }
     this.Cursor = Cursors.Default;
 }
Example #9
0
        private void button3_Click(object sender, EventArgs e)
        {
            WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;

            if (wpi != null)
            {
                Framework.Data.Waypoint wp = wpi.WP;
                Framework.Data.Location l;
                if (wp.Lat != null && wp.Lon != null)
                {
                    l = new Framework.Data.Location((double)wp.Lat, (double)wp.Lon);
                }
                else
                {
                    l = new Framework.Data.Location(Core.ActiveGeocache.Lat, Core.ActiveGeocache.Lon);
                }
                using (Utils.Dialogs.GetLocationForm dlg = new Utils.Dialogs.GetLocationForm(Core, l))
                {
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        textBox8.Text = Utils.Conversion.GetCoordinatesPresentation(dlg.Result);
                    }
                }
            }
        }
Example #10
0
 private void setAdditionalCoordsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (Core.ActiveGeocache != null)
     {
         Framework.Data.Location l = new Framework.Data.Location();
         if (Core.ActiveGeocache.ContainsCustomLatLon)
         {
             l.SetLocation((double)Core.ActiveGeocache.CustomLat, (double)Core.ActiveGeocache.CustomLon);
         }
         else
         {
             l.SetLocation(Core.ActiveGeocache.Lat, Core.ActiveGeocache.Lon);
         }
         using (Utils.Dialogs.GetLocationForm dlg = new Utils.Dialogs.GetLocationForm(Core, l))
         {
             if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 Core.ActiveGeocache.BeginUpdate();
                 Core.ActiveGeocache.CustomLat = dlg.Result.Lat;
                 Core.ActiveGeocache.CustomLon = dlg.Result.Lon;
                 Core.ActiveGeocache.EndUpdate();
             }
         }
     }
 }
Example #11
0
 public static Framework.Data.Location GetLocationOfAddress(string address)
 {
     Framework.Data.Location result = null;
     try
     {
         string         s  = null;
         HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", HttpUtility.UrlEncode(address)));
         wr.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
         wr.Method    = WebRequestMethods.Http.Get;
         using (HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse())
         {
             using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
             {
                 s = reader.ReadToEnd();
                 webResponse.Close();
             }
         }
         if (s != null && s.Length > 0)
         {
             XmlDocument xdoc = new XmlDocument();
             xdoc.LoadXml(s);
             XmlNode n = xdoc.SelectSingleNode("GeocodeResponse/result/geometry/location");
             result = new Framework.Data.Location();
             result.SetLocation(Conversion.StringToDouble(n.SelectSingleNode("lat").InnerText), Conversion.StringToDouble(n.SelectSingleNode("lng").InnerText));
         }
     }
     catch
     {
         result = null;
     }
     return(result);
 }
Example #12
0
        public List <Framework.Data.AreaInfo> GetEnvelopAreasOfLocation(Framework.Data.Location loc, List <Framework.Data.AreaInfo> inAreas)
        {
            List <Framework.Data.AreaInfo> result = null;

            if (loc.Lat >= _shpYMin && loc.Lat <= _shpYMax && loc.Lon >= _shpXMin && loc.Lon <= _shpXMax)
            {
                //all areas with point in envelope
                var ais = from r in _areaInfos
                          join b in inAreas on r equals b
                          where loc.Lat >= r.MinLat && loc.Lat <= r.MaxLat && loc.Lon >= r.MinLon && loc.Lon <= r.MaxLon
                          select r;
                foreach (var ai in ais)
                {
                    if (IsLocationInEnvelopArea(loc, ai))
                    {
                        if (result == null)
                        {
                            result = new List <Framework.Data.AreaInfo>();
                        }
                        result.Add(ai);
                    }
                }
            }
            return(result);
        }
Example #13
0
 private void buttonWithinRadius_Click(object sender, EventArgs e)
 {
     _withinRadius = true;
     try
     {
         if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
         {
             object o = webBrowser1.Document.InvokeScript("getCenterPosition");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString().Replace("(", "").Replace(")", "");
                 _center = Utils.Conversion.StringToLocation(s);
             }
             else
             {
                 return;
             }
             o = webBrowser1.Document.InvokeScript("getRadius");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString();
                 _radius = Utils.Conversion.StringToDouble(s);
             }
             else
             {
                 return;
             }
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
             Close();
         }
     }
     catch
     {
     }
 }
Example #14
0
        private bool IsLocationInEnvelopArea(Framework.Data.Location loc, Framework.Data.AreaInfo area)
        {
            bool result = false;

            //point in envelope of area
            if (loc.Lat >= area.MinLat && loc.Lat <= area.MaxLat && loc.Lon >= area.MinLon && loc.Lon <= area.MaxLon)
            {
                bool releasePoly = area.Polygons == null;
                if (area.Polygons == null)
                {
                    GetPolygonOfArea(area);
                }
                if (area.Polygons != null)
                {
                    foreach (var r in area.Polygons)
                    {
                        //point in envelope of polygon
                        if (loc.Lat >= r.MinLat && loc.Lat <= r.MaxLat && loc.Lon >= r.MinLon && loc.Lon <= r.MaxLon)
                        {
                            result = true;
                            break;
                        }
                    }
                }
                if (releasePoly)
                {
                    area.Polygons = null;
                }
            }
            return(result);
        }
        private void button4_Click(object sender, EventArgs e)
        {
            WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;

            Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox8.Text);
            if (Core.ActiveGeocache != null && wpi != null && wpi.WP.ID <= 0)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    try
                    {
                        Utils.API.LiveV6.SaveUserWaypointResponse resp = null;
                        Cursor = Cursors.WaitCursor;
                        try
                        {
                            using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                            {
                                var req = new Utils.API.LiveV6.SaveUserWaypointRequest();
                                req.AccessToken = api.Token;
                                req.CacheCode   = Core.ActiveGeocache.Code;
                                req.Description = textBox2.Text;
                                req.Latitude    = ll.Lat;
                                req.Longitude   = ll.Lon;
                                resp            = api.Client.SaveUserWaypoint(req);
                            }
                        }
                        finally
                        {
                            Cursor = Cursors.Default;
                        }
                        if (resp != null)
                        {
                            if (resp.Status.StatusCode == 0)
                            {
                                Framework.Data.UserWaypoint wp = Utils.API.Convert.UserWaypoint(Core, resp.NewWaypoint);
                                wp.Saved = false;
                                wpi.WP   = wp;
                                Core.UserWaypoints.Add(wp);
                            }
                            else
                            {
                                MessageBox.Show(resp.Status.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                            }
                        }
                        else
                        {
                            MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                        }
                    }
                    catch
                    {
                        MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
        }
Example #16
0
        public List <Framework.Data.AreaInfo> GetEnvelopAreasOfLocation(Framework.Data.Location loc, List <Framework.Data.AreaInfo> inAreas)
        {
            List <Framework.Data.AreaInfo> result = new List <Framework.Data.AreaInfo>();

            foreach (Framework.Interfaces.IGeometry g in _geometryPlugins)
            {
                result.AddRange(g.GetEnvelopAreasOfLocation(loc, inAreas));
            }
            return(result);
        }
Example #17
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 1, 1);
            Framework.Data.Location ll = Utils.Conversion.StringToLocation(args[0].ToString());
            if (ll != null)
            {
                return(ll.Lon.ToString("G", CultureInfo.InvariantCulture));
            }
            return("");
        }
Example #18
0
        public static Framework.Data.Location LocationFromRD(double x, double y)
        {
            Framework.Data.Location result = null;
            double lattitude;
            double longitude;

            if (LatLonFromRD(x, y, out lattitude, out longitude))
            {
                result = new Framework.Data.Location(lattitude, longitude);
            }
            return(result);
        }
Example #19
0
 private void textBoxLocation_TextChanged(object sender, EventArgs e)
 {
     Framework.Data.Location l = Utils.Conversion.StringToLocation(textBoxLocation.Text);
     if (l == null)
     {
         buttonOK.Enabled = false;
     }
     else
     {
         buttonOK.Enabled = true;
     }
 }
Example #20
0
        public static List <string> GetGeocachesWithinRadius(SiteInfo si, Framework.Data.Location loc, double radiusKm, string filter)
        {
            List <string> result;

            if (!string.IsNullOrEmpty(filter))
            {
                filter = string.Concat("&", filter);
            }
            string url = string.Format("{0}services/caches/search/nearest?center={1}|{2}&radius={3}{4}&limit=500&consumer_key={5}", si.OKAPIBaseUrl, loc.Lat.ToString().Replace(',', '.'), loc.Lon.ToString().Replace(',', '.'), radiusKm.ToString().Replace(',', '.'), filter, HttpUtility.UrlEncode(si.ConsumerKey));

            result = GetGeocachesByUrl(url);
            return(result);
        }
Example #21
0
        public List <Framework.Data.AreaInfo> GetEnvelopAreasOfLocation(Framework.Data.Location loc)
        {
            List <Framework.Data.AreaInfo> result = new List <Framework.Data.AreaInfo>();

            foreach (var sf in _shapeFiles)
            {
                List <Framework.Data.AreaInfo> areas = sf.GetEnvelopAreasOfLocation(loc);
                if (areas != null)
                {
                    result.AddRange(areas);
                }
            }
            return(result);
        }
Example #22
0
 public static Framework.Data.Location Convert2Location(string LatDegrees, string LatMinutes, string LonDegrees, string LonMinutes)
 {
     Framework.Data.Location result = new Framework.Data.Location();
     try
     {
         result.SetLocation(Conversion.StringToDouble(LatDegrees) + (Conversion.StringToDouble(LatMinutes) / 60.0),
                            Conversion.StringToDouble(LonDegrees) + (Conversion.StringToDouble(LonMinutes) / 60.0));
     }
     catch
     {
         result = null;
     }
     return(result);
 }
Example #23
0
 private void button6_Click(object sender, EventArgs e)
 {
     Framework.Data.Location l = Utils.Conversion.StringToLocation(textBox4.Text);
     if (l != null)
     {
         _core.Geocaches.BeginUpdate();
         foreach (Framework.Data.Geocache g in _gcList)
         {
             g.Lat = l.Lat;
             g.Lon = l.Lon;
         }
         _core.Geocaches.EndUpdate();
     }
 }
Example #24
0
 public static Framework.Data.Location Convert2Location(string LatDegrees, string LatMinutes, string LonDegrees, string LonMinutes)
 {
     Framework.Data.Location result = new Framework.Data.Location();
     try
     {
         result.SetLocation(Conversion.StringToDouble(LatDegrees) + (Conversion.StringToDouble(LatMinutes) / 60.0),
             Conversion.StringToDouble(LonDegrees) + (Conversion.StringToDouble(LonMinutes) / 60.0));
     }
     catch
     {
         result = null;
     }
     return result;
 }
Example #25
0
 private void calculateProjection()
 {
     Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox3.Text);
     if (ll != null)
     {
         GeodeticCalculator gc = new GeodeticCalculator();
         GlobalCoordinates  p  = gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(ll.Lat), new Angle(ll.Lon)), new Angle((double)numericUpDown2.Value), radioButton1.Checked ? (double)numericUpDown1.Value : 1609.26939 * (double)numericUpDown2.Value);
         textBox4.Text = Utils.Conversion.GetCoordinatesPresentation(p.Latitude.Degrees, p.Longitude.Degrees);
     }
     else
     {
         textBox4.Text = "";
     }
 }
Example #26
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            string          res     = "";
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 2, null);
            Framework.Data.Location ll1 = Utils.Conversion.StringToLocation(args[0].ToString());
            Framework.Data.Location ll2 = Utils.Conversion.StringToLocation(args[1].ToString());
            if ((ll1 != null) && (ll2 != null))
            {
                GeodeticMeasurement gm = Utils.Calculus.CalculateDistance(ll1.Lat, ll1.Lon, ll2.Lat, ll2.Lon);
                res = gm.Azimuth.Degrees.ToString("0");
            }
            return(res);
        }
Example #27
0
 public void UpdateStatus(Framework.Data.GPSLocation loc)
 {
     if (loc.Valid != button2.Enabled)
     {
         button2.Enabled = loc.Valid;
     }
     if (loc.Valid)
     {
         _activePosition = loc.Position;
         label4.Text     = Utils.Conversion.GetCoordinatesPresentation(_activePosition);
     }
     else
     {
         label4.Text = "?";
     }
 }
Example #28
0
 public void UpdateStatus(Framework.Data.GPSLocation loc)
 {
     if (loc.Valid != button2.Enabled)
     {
         button2.Enabled = loc.Valid;
     }
     if (loc.Valid)
     {
         _activePosition = loc.Position;
         label4.Text = Utils.Conversion.GetCoordinatesPresentation(_activePosition);
     }
     else
     {
         label4.Text = "?";
     }
 }
Example #29
0
        /// <summary>
        /// The distance of a point from a line made from point1 and point2.
        /// </summary>
        /// <param name="pt1">The PT1.</param>
        /// <param name="pt2">The PT2.</param>
        /// <param name="p">The p.</param>
        /// <returns></returns>
        public static Double PerpendicularDistance
            (Framework.Data.Location Point1, Framework.Data.Location Point2, Framework.Data.Location Point)
        {
            //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)|   *Area of triangle
            //Base = v((x1-x2)²+(x1-x2)²)                               *Base of Triangle*
            //Area = .5*Base*H                                          *Solve for height
            //Height = Area/.5/Base

            Double area = Math.Abs(.5 * (Point1.Lon * Point2.Lat + Point2.Lon *
                                         Point.Lat + Point.Lon * Point1.Lat - Point2.Lon * Point1.Lat - Point.Lon *
                                         Point2.Lat - Point1.Lon * Point.Lat));
            Double bottom = Math.Sqrt(Math.Pow(Point1.Lon - Point2.Lon, 2) +
                                      Math.Pow(Point1.Lat - Point2.Lat, 2));
            Double height = area / bottom * 2;

            return(height);

            //Another option
            //Double A = Point.X - Point1.X;
            //Double B = Point.Y - Point1.Y;
            //Double C = Point2.X - Point1.X;
            //Double D = Point2.Y - Point1.Y;

            //Double dot = A * C + B * D;
            //Double len_sq = C * C + D * D;
            //Double param = dot / len_sq;

            //Double xx, yy;

            //if (param < 0)
            //{
            //    xx = Point1.X;
            //    yy = Point1.Y;
            //}
            //else if (param > 1)
            //{
            //    xx = Point2.X;
            //    yy = Point2.Y;
            //}
            //else
            //{
            //    xx = Point1.X + param * C;
            //    yy = Point1.Y + param * D;
            //}

            //Double d = DistanceBetweenOn2DPlane(Point, new Point(xx, yy));
        }
Example #30
0
        public static Framework.Data.Location LocationFromString(string s)
        {
            Framework.Data.Location result = null;
            try
            {
                s = s.ToUpper();
                string[] parts = s.Split(new char[] { ' ', 'N', 'E', 'S', 'W', '.', '°', ',', '\'' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 6 || parts.Length == 4)
                {
                    double lat;
                    double lon;
                    Framework.Data.Location ll = new Framework.Data.Location();
                    if (parts.Length == 6)
                    {
                        lat = Conversion.StringToDouble(parts[0]) + ((Conversion.StringToDouble(parts[1]) + (Conversion.StringToDouble(parts[2]) / 1000.0)) / 60.0);
                        lon = Conversion.StringToDouble(parts[3]) + ((Conversion.StringToDouble(parts[4]) + (Conversion.StringToDouble(parts[5]) / 1000.0)) / 60.0);

                        if (s.IndexOf("S", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            lat = -1.0 * lat;
                        }
                        if (s.IndexOf("W", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            lon = -1.0 * lon;
                        }
                    }
                    else
                    {
                        lat = Conversion.StringToDouble(string.Format("{0},{1}", parts[0], parts[1]));
                        lon = Conversion.StringToDouble(string.Format("{0},{1}", parts[2], parts[3]));
                    }
                    result = new Framework.Data.Location();
                    result.SetLocation(lat, lon);
                }
                else if (parts.Length == 2)
                {
                    double x = Conversion.StringToDouble(parts[0]);
                    double y = Conversion.StringToDouble(parts[1]);
                    result = LocationFromRD(x, y);
                }
            }
            catch
            {
            }
            return(result);
        }
Example #31
0
        public static Framework.Data.Location LocationFromString(string s)
        {
            Framework.Data.Location result = null;
            try
            {
                s = s.ToUpper();
                string[] parts = s.Split(new char[] { ' ', 'N', 'E', 'S', 'W', '.', '°', ',', '\'' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 6 || parts.Length == 4)
                {
                    double lat;
                    double lon;
                    Framework.Data.Location ll = new Framework.Data.Location();
                    if (parts.Length == 6)
                    {
                        lat = Conversion.StringToDouble(parts[0]) + ((Conversion.StringToDouble(parts[1]) + (Conversion.StringToDouble(parts[2]) / 1000.0)) / 60.0);
                        lon = Conversion.StringToDouble(parts[3]) + ((Conversion.StringToDouble(parts[4]) + (Conversion.StringToDouble(parts[5]) / 1000.0)) / 60.0);

                        if (s.IndexOf("S", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            lat = -1.0 * lat;
                        }
                        if (s.IndexOf("W", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            lon = -1.0 * lon;
                        }
                    }
                    else
                    {
                        lat = Conversion.StringToDouble(string.Format("{0},{1}", parts[0], parts[1]));
                        lon = Conversion.StringToDouble(string.Format("{0},{1}", parts[2], parts[3]));
                    }
                    result = new Framework.Data.Location();
                    result.SetLocation(lat, lon);
                }
                else if (parts.Length == 2)
                {
                    double x = Conversion.StringToDouble(parts[0]);
                    double y = Conversion.StringToDouble(parts[1]);
                    result = LocationFromRD(x, y);
                }
            }
            catch
            {
            }
            return result;
        }
Example #32
0
 private void calculateAngleAndDegrees()
 {
     Framework.Data.Location ll1 = Utils.Conversion.StringToLocation(textBox5.Text);
     Framework.Data.Location ll2 = Utils.Conversion.StringToLocation(textBox6.Text);
     if (ll1 != null && ll2 != null)
     {
         GeodeticMeasurement gm = Utils.Calculus.CalculateDistance(ll1.Lat, ll1.Lon, ll2.Lat, ll2.Lon);
         textBox7.Text = gm.EllipsoidalDistance.ToString("0");
         textBox8.Text = (0.0006214 * gm.EllipsoidalDistance).ToString("0.000");
         textBox9.Text = gm.Azimuth.Degrees.ToString("0");
     }
     else
     {
         textBox7.Text = "";
         textBox8.Text = "";
         textBox9.Text = "";
     }
 }
Example #33
0
        public GetLocationForm(Framework.Interfaces.ICore core, Framework.Data.Location defaultLoc)
        {
            InitializeComponent();

            this.Text = LanguageSupport.Instance.GetTranslation(STR_GET_LOCATION);
            this.labelLocation.Text    = LanguageSupport.Instance.GetTranslation(STR_LOCATION);
            this.buttonOK.Text         = LanguageSupport.Instance.GetTranslation(STR_OK);
            this.buttonMap.Text        = LanguageSupport.Instance.GetTranslation(STR_MAP);
            this.buttonFromHome.Text   = LanguageSupport.Instance.GetTranslation(STR_FROMHOMELOC);
            this.buttonFromCenter.Text = LanguageSupport.Instance.GetTranslation(STR_FROMCENTERLOC);

            _core = core;
            if (defaultLoc != null)
            {
                _loc = new Framework.Data.Location(defaultLoc.Lat, defaultLoc.Lon);
                textBoxLocation.Text = Utils.Conversion.GetCoordinatesPresentation(_loc);
            }
        }
Example #34
0
        public GetLocationForm(Framework.Interfaces.ICore core, Framework.Data.Location defaultLoc)
        {
            InitializeComponent();

            this.Text = LanguageSupport.Instance.GetTranslation(STR_GET_LOCATION);
            this.labelLocation.Text = LanguageSupport.Instance.GetTranslation(STR_LOCATION);
            this.buttonOK.Text = LanguageSupport.Instance.GetTranslation(STR_OK);
            this.buttonMap.Text = LanguageSupport.Instance.GetTranslation(STR_MAP);
            this.buttonFromHome.Text = LanguageSupport.Instance.GetTranslation(STR_FROMHOMELOC);
            this.buttonFromCenter.Text = LanguageSupport.Instance.GetTranslation(STR_FROMCENTERLOC);

            _core = core;
            if (defaultLoc != null)
            {
                _loc = new Framework.Data.Location(defaultLoc.Lat, defaultLoc.Lon);
                textBoxLocation.Text = Utils.Conversion.GetCoordinatesPresentation(_loc);
            }
        }
Example #35
0
 private void button1_Click(object sender, EventArgs e)
 {
     Framework.Data.Location ll = null;
     if (textBoxCenterLocation.Text.Length > 0)
     {
         ll = Utils.Conversion.StringToLocation(textBoxCenterLocation.Text);
         if (ll == null)
         {
             ll = Utils.Geocoder.GetLocationOfAddress(textBoxCenterLocation.Text);
             if (ll == null)
             {
                 textBoxCenterLocation.Text = "";
             }
             else
             {
                 textBoxCenterLocation.Text = Utils.Conversion.GetCoordinatesPresentation(ll);
             }
         }
     }
 }
Example #36
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            string          ret     = "";
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 3, null);
            Framework.Data.Location ll = Utils.Conversion.StringToLocation(args[0].ToString());
            double distance            = Utils.Conversion.StringToDouble(args[1].ToString());
            double angle = Utils.Conversion.StringToDouble(args[2].ToString());

            if (ll != null)
            {
                GeodeticCalculator gc = new GeodeticCalculator();
                GlobalCoordinates  p  = gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84,
                                                                            new GlobalCoordinates(new Angle(ll.Lat), new Angle(ll.Lon)),
                                                                            new Angle(angle), distance);
                ret = Utils.Conversion.GetCoordinatesPresentation(p.Latitude.Degrees, p.Longitude.Degrees);
            }

            return(ret);
        }
Example #37
0
 private void setAdditionalCoordsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (Core.ActiveGeocache != null)
     {
         Framework.Data.Location l = new Framework.Data.Location();
         if (Core.ActiveGeocache.ContainsCustomLatLon)
         {
             l.SetLocation((double)Core.ActiveGeocache.CustomLat, (double)Core.ActiveGeocache.CustomLon);
         }
         else
         {
             l.SetLocation(Core.ActiveGeocache.Lat, Core.ActiveGeocache.Lon);
         }
         using (Utils.Dialogs.GetLocationForm dlg = new Utils.Dialogs.GetLocationForm(Core, l))
         {
             if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 Core.ActiveGeocache.BeginUpdate();
                 Core.ActiveGeocache.CustomLat = dlg.Result.Lat;
                 Core.ActiveGeocache.CustomLon = dlg.Result.Lon;
                 Core.ActiveGeocache.EndUpdate();
             }
         }
     }
 }
Example #38
0
 public async override Task<bool> ActionAsync(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_IMPORT)
     {
         if (SiteManager.Instance.CheckAPIAccess())
         {
             using (ImportByRadiusForm dlg = new ImportByRadiusForm(Core))
             {
                 if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
                     _filter = dlg.Filter;
                     _radiusKm = dlg.RadiusKm;
                     _centerLoc = dlg.Center;
                     await PerformImport();
                     if (!string.IsNullOrEmpty(_errormessage))
                     {
                         System.Windows.Forms.MessageBox.Show(_errormessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                     }
                 }
             }
         }
     }
     return result;
 }
Example #39
0
        public Engine()
        {
            try
            {
                _settingsProvider = new SettingsProvider(null);

                string[] args = Environment.GetCommandLineArgs();
                if (EnablePluginDataPathAtStartup || (args != null && args.Contains("/f")))
                {
                    using (SelectSettingsForm dlg = new SelectSettingsForm(this))
                    {
                        _pluginDataFolderSelected = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    _pluginDataFolderSelected = true;
                }

                if (_pluginDataFolderSelected)
                {
                    _geocachingAccountNames = new Framework.Data.GeocachingAccountNames();
                    var p = _settingsProvider.GetSettingsValueStringCollection("Core.GeocachingAccountNames", null);
                    if (p != null)
                    {
                        foreach (string s in p)
                        {
                            string[] parts = s.Split("|".ToArray(), 2);
                            if (parts.Length == 2)
                            {
                                _geocachingAccountNames.SetAccountName(parts[0], parts[1]);
                            }
                        }
                    }
                    _geocachingAccountNames.Changed += new Framework.EventArguments.GeocachingAccountNamesEventHandler(_geocachingAccountNames_Changed);

                    _geocachingComAccount = new Framework.Data.GeocachingComAccountInfo();
                    _geocachingComAccount.AccountName = _settingsProvider.GetSettingsValue("Core.GCComAccountName", null);
                    _geocachingComAccount.APIToken = _settingsProvider.GetSettingsValue("Core.GCComAccountToken", null);
                    _geocachingComAccount.APITokenStaging = _settingsProvider.GetSettingsValue("Core.GCComAccountTokenStaging", null);
                    _geocachingComAccount.MemberType = _settingsProvider.GetSettingsValue("Core.GCComAccountMemberType", null);
                    _geocachingComAccount.MemberTypeId = _settingsProvider.GetSettingsValueInt("Core.GCComAccountMemberTypeId", 0);
                    _geocachingComAccount.Changed += new Framework.EventArguments.GeocacheComAccountEventHandler(_geocachingComAccount_Changed);
                    GeocachingAccountNames.SetAccountName("GC", _settingsProvider.GetSettingsValue("Core.GCComAccountName", null) ?? "");

                    _logs = new Framework.Data.LogCollection();
                    _userWaypoints = new Framework.Data.UserWaypointCollection();
                    _waypoints = new Framework.Data.WaypointCollection();
                    _geocaches = new Framework.Data.GeocacheCollection(this);
                    _logImages = new Framework.Data.LogImageCollection();
                    _geocacheImages = new Framework.Data.GeocacheImageCollection();
                    _geocacheAttributes = new Framework.Data.GeocacheAttributeCollection();
                    _geocacheTypes = new Framework.Data.GeocacheTypeCollection();
                    _geocacheContainers = new Framework.Data.GeocacheContainerCollection();
                    _logTypes = new Framework.Data.LogTypeCollection();
                    _waypointTypes = new Framework.Data.WaypointTypeCollection();
                    _homeLocation = new Framework.Data.Location();
                    _centerLocation = new Framework.Data.Location();
                    _gpsLocation = new Framework.Data.GPSLocation();
                    _languageItems = new Framework.Data.LanguageItemCollection();

                    _detectedPlugins = new List<string>();
                    _internalStoragePlugins = new List<string>();
                    _selectedLanguage = System.Globalization.CultureInfo.CurrentCulture;
                    _plugins = new List<Framework.Interfaces.IPlugin>();
                    _currentDomain = AppDomain.CurrentDomain;
                    _currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);

                    //set initial data
                    //default location settings
                    _centerLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.CenterLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.CenterLon", 5.5));
                    _centerLocation.Changed += new Framework.EventArguments.LocationEventHandler(_centerLocation_Changed);
                    _homeLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.HomeLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.HomeLon", 5.5));
                    _homeLocation.Changed += new Framework.EventArguments.LocationEventHandler(_homeLocation_Changed);

                    //default (unknown) cache- ,container etc. types. Position 0 means unknown
                    Framework.Data.GeocacheType ct = new Framework.Data.GeocacheType();
                    ct.ID = 0;
                    ct.Name = "Not present";
                    _geocacheTypes.Add(ct);
                    Framework.Data.GeocacheAttribute attr = new Framework.Data.GeocacheAttribute();
                    attr.ID = 0;
                    attr.Name = "Unknown";
                    _geocacheAttributes.Add(attr);
                    Framework.Data.GeocacheContainer cont = new Framework.Data.GeocacheContainer();
                    cont.ID = 0;
                    cont.Name = "Unknown";
                    _geocacheContainers.Add(cont);
                    Framework.Data.LogType lt = new Framework.Data.LogType();
                    lt.ID = 0;
                    lt.Name = "Unknown";
                    lt.AsFound = false;
                    _logTypes.Add(lt);
                    Framework.Data.WaypointType wpt = new Framework.Data.WaypointType();
                    wpt.ID = 0;
                    wpt.Name = "Unknown";
                    _waypointTypes.Add(wpt);

                    _shortcuts = new List<Framework.Data.ShortcutInfo>();
                }
            }
            catch
            {
                RestoreDefaultSettings();
            }
        }
Example #40
0
 public override bool PrepareRun()
 {
     if (Values.Count > 1)
     {
         try
         {
             _loc = Utils.Conversion.StringToLocation(Values[0]);
             _value = Utils.Conversion.StringToDouble(Values[1]);
         }
         catch
         {
         }
     }
     return base.PrepareRun();
 }
Example #41
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     _loc = Utils.Conversion.StringToLocation(textBoxLocation.Text);
 }
Example #42
0
 private void buttonWithinRadius_Click(object sender, EventArgs e)
 {
     _withinRadius = true;
     try
     {
         if (_webBrowser.IsReady)
         {
             object o = _webBrowser.InvokeScript("getCenterPosition()");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString().Replace("(", "").Replace(")", "");
                 _center = Utils.Conversion.StringToLocation(s);
             }
             o = _webBrowser.InvokeScript("getRadius()");
             if (o != null && o.GetType() != typeof(DBNull))
             {
                 string s = o.ToString();
                 _radius = Utils.Conversion.StringToDouble(s);
             }
         }
     }
     catch
     {
     }
 }
 private void button5_Click(object sender, EventArgs e)
 {
     WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;
     if (wpi != null)
     {
         Framework.Data.UserWaypoint wp = wpi.WP;
         Framework.Data.Location l = new Framework.Data.Location(wp.Lat, wp.Lon);
         using (Utils.Dialogs.GetLocationForm dlg = new Utils.Dialogs.GetLocationForm(Core, l))
         {
             if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 textBox8.Text = Utils.Conversion.GetCoordinatesPresentation(dlg.Result);
             }
         }
     }
 }
Example #44
0
        public static Framework.Data.Location StringToLocation(string s)
        {
            Framework.Data.Location result = null;
            try
            {
                double Lat;
                double Lon;
                string[] parts = s.Split(new char[] { ' ', 'N', 'E', 'S', 'W', '.', '°', ',', '\'', '/' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 6 || parts.Length == 4)
                {
                    if (parts.Length == 6)
                    {
                        Lat = StringToDouble(parts[0]) + ((StringToDouble(parts[1]) + (StringToDouble(parts[2]) / 1000.0)) / 60.0);
                        Lon = StringToDouble(parts[3]) + ((StringToDouble(parts[4]) + (StringToDouble(parts[5]) / 1000.0)) / 60.0);

                        if (s.IndexOf("S", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            Lat = -1.0 * Lat;
                        }
                        if (s.IndexOf("W", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            Lon = -1.0 * Lon;
                        }
                    }
                    else
                    {
                        Lat = StringToDouble(string.Format("{0},{1}", parts[0], parts[1]));
                        Lon = StringToDouble(string.Format("{0},{1}", parts[2], parts[3]));
                    }
                    result = new Framework.Data.Location(Lat, Lon);

                }
            }
            catch
            {
            }
            return result;
        }
Example #45
0
 public static Framework.Data.Location LocationFromRD(double x, double y)
 {
     Framework.Data.Location result = null;
     double lattitude;
     double longitude;
     if (LatLonFromRD(x, y, out lattitude, out longitude))
     {
         result = new Framework.Data.Location(lattitude, longitude);
     }
     return result;
 }