Example #1
0
        public bool SetLocation(FactLocation loc, int level)
        {
            while (!loaded)
            {
                Application.DoEvents();
            }
            GeoResponse.CResult.CGeometry.CViewPort viewport = null;
            GeoResponse res = null;

            Object[] args = new Object[] { 0, 0 };
            if (loc.IsGeoCoded(false) && loc.ViewPort != null)
            {
                labMapLevel.Text = "Previously Geocoded: " + loc.ToString();
                viewport         = MapTransforms.ReverseTransformViewport(loc.ViewPort);
                args             = new Object[] { loc.Latitude, loc.Longitude };
            }
            else
            {
                location = loc.ToString();
                res      = CallGoogleGeocode(location);
                if (res.Status == "OK")
                {
                    labMapLevel.Text = GoogleMap.LocationText(res, loc, level);
                    viewport         = res.Results[0].Geometry.ViewPort;
                    double lat = res.Results[0].Geometry.Location.Lat;
                    double lng = res.Results[0].Geometry.Location.Long;
                    args = new Object[] { lat, lng };
                }
                else if (res.Status == "OVER_QUERY_LIMIT" && loc.IsGeoCoded(false))
                {
                    labMapLevel.Text        = "Previously Geocoded: " + loc.ToString();
                    viewport                = new GeoResponse.CResult.CGeometry.CViewPort();
                    viewport.NorthEast.Lat  = loc.Latitude + 2;
                    viewport.NorthEast.Long = loc.Longitude + 2;
                    viewport.SouthWest.Lat  = loc.Latitude - 2;
                    viewport.SouthWest.Long = loc.Longitude - 2;
                    args = new Object[] { loc.Latitude, loc.Longitude };
                }
                else
                {
                    return(false);
                }
            }
            Object marker = webBrowser.Document.InvokeScript("frontAndCenter", args);

            args = new Object[] { viewport.NorthEast.Lat, viewport.NorthEast.Long, viewport.SouthWest.Lat, viewport.SouthWest.Long };
            webBrowser.Document.InvokeScript("setViewport", args);
            webBrowser.Show();
            return(true);
        }
Example #2
0
 public bool SetLocation(FactLocation loc, int level)
 {
     if (loc is null)
     {
         return(false);
     }
     while (!loaded)
     {
         Application.DoEvents();
     }
     GeoResponse.CResult.CGeometry.CViewPort viewport;
     if (loc.IsGeoCoded(false) && loc.ViewPort != null)
     {
         labMapLevel.Text = "Previously Geocoded: " + loc.ToString();
         viewport         = MapTransforms.ReverseTransformViewport(loc.ViewPort);
     }
     else
     {
         GeoResponse res = GoogleMap.CallGoogleGeocode(loc, loc.ToString());
         if (res.Status == "OK")
         {
             labMapLevel.Text = GoogleMap.LocationText(res, loc, level);
             viewport         = res.Results[0].Geometry.ViewPort;
         }
         else if (res.Status == "OVER_QUERY_LIMIT" && loc.IsGeoCoded(false))
         {
             labMapLevel.Text        = "Previously Geocoded: " + loc.ToString();
             viewport                = new GeoResponse.CResult.CGeometry.CViewPort();
             viewport.NorthEast.Lat  = loc.Latitude + 2;
             viewport.NorthEast.Long = loc.Longitude + 2;
             viewport.SouthWest.Lat  = loc.Latitude + 2;
             viewport.SouthWest.Long = loc.Longitude + 2;
         }
         else
         {
             return(false);
         }
     }
     object[] args = new object[] { viewport.NorthEast.Lat, viewport.NorthEast.Long, viewport.SouthWest.Lat, viewport.SouthWest.Long };
     webBrowser.Document.InvokeScript("setBounds", args);
     webBrowser.Show();
     return(true);
 }
Example #3
0
        void UpdateDatabase()
        {
            Envelope   env   = new Envelope(mapBox1.Map.Envelope.TopLeft(), mapBox1.Map.Envelope.BottomRight());
            Coordinate point = MapTransforms.ReverseTransformCoordinate(pointFeature.Geometry.Coordinate);

            location.Latitude                = point.Y;
            location.Longitude               = point.X;
            location.LatitudeM               = pointFeature.Geometry.Coordinate.Y;
            location.LongitudeM              = pointFeature.Geometry.Coordinate.X;
            location.ViewPort.NorthEast.Lat  = env.Top();
            location.ViewPort.NorthEast.Long = env.Right();
            location.ViewPort.SouthWest.Lat  = env.Bottom();
            location.ViewPort.SouthWest.Long = env.Left();
            location.PixelSize               = mapBox1.Map.PixelSize;
            location.FoundLocation           = string.Empty;
            location.GeocodeStatus           = FactLocation.Geocode.GEDCOM_USER;
            location.FoundLevel              = -2;
            DatabaseHelper.UpdateGeocode(location);
            pointUpdated = false;
            dataUpdated  = true;
        }
Example #4
0
 void GoogleLocationSearch()
 {
     if (txtSearch.Text.Length > 0)
     {
         FactLocation loc = FactLocation.LookupLocation(txtSearch.Text);
         if (!loc.IsGeoCoded(false)) // if not geocoded then try database
         {
             DatabaseHelper.GetLocationDetails(loc);
         }
         if (loc.IsGeoCoded(false))
         {
             FactLocation.CopyLocationDetails(loc, location);
             SetLocation();
             pointUpdated = true;
         }
         else
         {
             GeoResponse res = GoogleMap.GoogleGeocode(txtSearch.Text, 8);
             if (res.Status == "OK" && !(res.Results[0].Geometry.Location.Lat == 0 && res.Results[0].Geometry.Location.Long == 0))
             {
                 loc.Latitude  = res.Results[0].Geometry.Location.Lat;
                 loc.Longitude = res.Results[0].Geometry.Location.Long;
                 Coordinate mpoint = MapTransforms.TransformCoordinate(new Coordinate(loc.Longitude, loc.Latitude));
                 loc.LongitudeM    = mpoint.X;
                 loc.LatitudeM     = mpoint.Y;
                 loc.ViewPort      = MapTransforms.TransformViewport(res.Results[0].Geometry.ViewPort);
                 loc.GeocodeStatus = res.Results[0].PartialMatch ? FactLocation.Geocode.PARTIAL_MATCH : FactLocation.Geocode.MATCHED;
                 FactLocation.CopyLocationDetails(loc, location);
                 SetLocation();
                 pointUpdated = true;
             }
             else
             {
                 MessageBox.Show("Google didn't find " + txtSearch.Text, "Failed Google Lookup");
             }
         }
     }
 }
        void ConvertLatLongs()
        {
            Coordinate Point, NorthEast, SouthWest;
            Coordinate mPoint, mNorthEast, mSouthWest;
            double     latitude, longitude, viewport_x_ne, viewport_y_ne, viewport_x_sw, viewport_y_sw;

            if (InstanceConnection.State != ConnectionState.Open)
            {
                InstanceConnection.Open();
            }
            int rowcount = 0;

            using (SQLiteCommand cmd = new SQLiteCommand("select count(*) from geocode where latitude <> 0 and longitude <> 0", InstanceConnection))
            {
                using (SQLiteDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleResult))
                {
                    reader.Read();
                    int.TryParse(reader[0].ToString(), out rowcount);
                }
            }
            #region update cmd
            using (SQLiteCommand updateCmd = new SQLiteCommand("update geocode set latm=?, longm=?, viewport_x_ne=?, viewport_y_ne=?, viewport_x_sw=?, viewport_y_sw=?  where location = ?", InstanceConnection))
            {
                SQLiteParameter param = updateCmd.CreateParameter();
                param.DbType = DbType.Double;
                updateCmd.Parameters.Add(param);

                param        = updateCmd.CreateParameter();
                param.DbType = DbType.Double;
                updateCmd.Parameters.Add(param);

                param        = updateCmd.CreateParameter();
                param.DbType = DbType.Double;
                updateCmd.Parameters.Add(param);

                param        = updateCmd.CreateParameter();
                param.DbType = DbType.Double;
                updateCmd.Parameters.Add(param);

                param        = updateCmd.CreateParameter();
                param.DbType = DbType.Double;
                updateCmd.Parameters.Add(param);

                param        = updateCmd.CreateParameter();
                param.DbType = DbType.Double;
                updateCmd.Parameters.Add(param);

                param        = updateCmd.CreateParameter();
                param.DbType = DbType.String;
                updateCmd.Parameters.Add(param);
                updateCmd.Prepare();
                Progress p = new Progress(rowcount);
                p.Show();
                int row = 0;
                using (SQLiteCommand cmd = new SQLiteCommand("select location, latitude, longitude, viewport_x_ne, viewport_y_ne, viewport_x_sw, viewport_y_sw from geocode where latitude <> 0 and longitude <> 0", InstanceConnection))
                {
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            latitude = longitude = viewport_x_ne = viewport_x_sw = viewport_y_ne = viewport_y_sw = 0;
                            string location = reader["location"].ToString();
                            double.TryParse(reader["latitude"].ToString(), out latitude);
                            double.TryParse(reader["longitude"].ToString(), out longitude);
                            double.TryParse(reader["viewport_x_ne"].ToString(), out viewport_x_ne);
                            double.TryParse(reader["viewport_y_ne"].ToString(), out viewport_y_ne);
                            double.TryParse(reader["viewport_x_sw"].ToString(), out viewport_x_sw);
                            double.TryParse(reader["viewport_y_sw"].ToString(), out viewport_y_sw);
                            Point      = new Coordinate(longitude, latitude);
                            NorthEast  = new Coordinate(viewport_y_ne, viewport_x_ne); // old viewports had x & y wrong way round
                            SouthWest  = new Coordinate(viewport_y_sw, viewport_x_sw); // x is stored as lat y as long
                            mPoint     = MapTransforms.TransformCoordinate(Point);
                            mNorthEast = MapTransforms.TransformCoordinate(NorthEast);
                            mSouthWest = MapTransforms.TransformCoordinate(SouthWest);
                            // now write back the m versions
                            updateCmd.Parameters[0].Value = mPoint.Y;
                            updateCmd.Parameters[1].Value = mPoint.X;
                            updateCmd.Parameters[2].Value = mNorthEast.X;
                            updateCmd.Parameters[3].Value = mNorthEast.Y;
                            updateCmd.Parameters[4].Value = mSouthWest.X;
                            updateCmd.Parameters[5].Value = mSouthWest.Y;
                            updateCmd.Parameters[6].Value = location;
                            updateCmd.ExecuteNonQuery();
                            p.Update(++row);
                        }
                    }
                }
                p.Dispose();
            }
            #endregion
        }