Пример #1
0
        public static GeoResponse CallGoogleGeocode(FactLocation address, string text)
        {
            string bounds = string.Empty;
            string tld    = address.IsUnitedKingdom ? "&region=uk" : string.Empty;

            if (address != null)
            {
                //if (address.Level > FactLocation.SUBREGION)
                //{
                //    FactLocation area = address.GetLocation(FactLocation.SUBREGION);
                //    if (area != null && area.IsGeoCoded(false) && !string.IsNullOrEmpty(area.Bounds))
                //        bounds = $"{area.Bounds}";
                //}
                if (string.IsNullOrEmpty(bounds) && address.Level > FactLocation.REGION)
                {
                    FactLocation area = address.GetLocation(FactLocation.REGION);
                    if (area != null && area.IsGeoCoded(false) && !string.IsNullOrEmpty(area.Bounds))
                    {
                        bounds = $"{area.Bounds}";
                    }
                }
                if (string.IsNullOrEmpty(bounds) && address.Level > FactLocation.COUNTRY)
                {
                    FactLocation area = address.GetLocation(FactLocation.COUNTRY);
                    if (area != null && area.IsGeoCoded(false) && !string.IsNullOrEmpty(area.Bounds))
                    {
                        bounds = $"{area.Bounds}";
                    }
                }
            }
            string encodedAddress = HttpUtility.UrlEncode(text.Replace(" ", "+"));
            string url            = $"https://maps.googleapis.com/maps/api/geocode/json?address={encodedAddress}{bounds}{tld}&key={GoogleAPIKey.KeyValue}";

            return(GetGeoResponse(url));
        }
Пример #2
0
        public static List <MapLocation> YearMapLocations(FactDate when, int limit)
        {
            List <MapLocation> result = new List <MapLocation>();

            foreach (Individual ind in FamilyTree.Instance.AllIndividuals)
            {
                if (ind.IsAlive(when) && ind.GetMaxAge(when) < FactDate.MAXYEARS)
                {
                    Fact         fact = ind.BestLocationFact(when, limit);
                    FactLocation loc  = fact.Location;
                    if (loc.IsGeoCoded(false))
                    {
                        result.Add(new MapLocation(ind, fact, when));
                    }
                    else
                    {
                        int startlevel = loc.Level - 1;
                        for (int level = startlevel; level > FactLocation.UNKNOWN; level--)
                        {
                            loc = loc.GetLocation(level);
                            if (loc.IsGeoCoded(false))
                            {
                                result.Add(new MapLocation(ind, fact, loc, when));
                                break;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #3
0
        public static void StoreLostCousinsFact(CensusIndividual ind, IProgress <string> outputText)
        {
            try
            {
                if (InstanceConnection.State != ConnectionState.Open)
                {
                    InstanceConnection.Open();
                }
                SqliteParameter param;

                using (SqliteCommand cmd = new SqliteCommand("insert into LostCousins (CensusYear, CensusCountry, CensusRef, IndID, FullName) values(?,?,?,?,?)", InstanceConnection))
                {
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.Int32;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    cmd.Prepare();

                    if (ind.CensusReference != null)
                    {
                        cmd.Parameters[0].Value = ind.CensusDate.BestYear;
                        cmd.Parameters[1].Value = ind.CensusCountry;
                        cmd.Parameters[2].Value = ind.CensusReference;
                        cmd.Parameters[3].Value = ind.IndividualID;
                        cmd.Parameters[4].Value = ind.Name;

                        int rowsaffected = cmd.ExecuteNonQuery();
                        if (rowsaffected != 1)
                        {
                            outputText.Report($"\nProblem updating record in database update affected {rowsaffected} records.");
                        }
                        else
                        {
                            FactLocation location = FactLocation.GetLocation(ind.CensusCountry);
                            Fact         f        = new Fact(ind.CensusRef, Fact.LC_FTA, ind.CensusDate, location, string.Empty, true, true);
                            Individual   person   = FamilyTree.Instance.GetIndividual(ind.IndividualID); // get the individual not the census indvidual
                            person?.AddFact(f);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                outputText.Report($"\nFailed to save Lost Cousins record in database error was: {e.Message}");
            }
        }
Пример #4
0
        public ScottishParish(string RD, string name, string region)
        {
            this.RD     = RD;
            this.Name   = name;
            this.Region = region;
            string loc = name + ", " + region + ", Scotland";

            this.Location = FactLocation.GetLocation(loc, false);
        }
        static void AddLostCousinsFact(CensusIndividual ind)
        {
            FactLocation location = FactLocation.GetLocation(ind.CensusCountry);
            Fact         f        = new Fact(ind.CensusRef, Fact.LC_FTA, ind.CensusDate, location, string.Empty, true, true);
            Individual   person   = FamilyTree.Instance.GetIndividual(ind.IndividualID); // get the individual not the census indvidual

            if (person != null && !person.HasLostCousinsFactAtDate(ind.CensusDate))
            {
                person.AddFact(f);
            }
        }
Пример #6
0
        public static string LocationText(GeoResponse res, FactLocation loc, int level)
        {
            string output;
            int    returnlevel = GetFactLocationType(res.Results[0].Types, loc);

            if (returnlevel != FactLocation.UNKNOWN)
            {
                output = $"Google found {loc.GetLocation(returnlevel)}";
                // if we have different input and output levels, assuming it isn't just a more accurate place in the address field
                // then also show what Google found
                if (level != returnlevel && !(level == FactLocation.ADDRESS && returnlevel >= FactLocation.ADDRESS))
                {
                    output += $" as {res.Results[0].ReturnAddress}";
                }
            }
            else
            {
                output = $"Best guess for {loc.GetLocation(level)} is {res.Results[0].ReturnAddress}";
            }
            return(output);
        }
Пример #7
0
 private void SetCommentAndLocation(string factType, string factComment, string factPlace, string latitude, string longitude)
 {
     if (factComment.Length == 0 && factPlace.Length > 0)
     {
         if (factPlace.EndsWith("/"))
         {
             Comment = factPlace.Substring(0, factPlace.Length - 1);
             Place   = string.Empty;
         }
         else
         {
             int slash = factPlace.IndexOf("/");
             if (slash >= 0)
             {
                 Comment = factPlace.Substring(0, slash).Trim();
                 // If slash occurs at end of string, location is empty.
                 Place = (slash == factPlace.Length - 1) ? string.Empty : factPlace.Substring(slash + 1).Trim();
             }
             else if (Fact.COMMENT_FACTS.Contains(factType))
             {
                 // we have a comment rather than a location
                 Comment = factPlace;
                 Place   = string.Empty;
             }
             else
             {
                 Comment = string.Empty;
                 Place   = factPlace;
             }
         }
     }
     else
     {
         Comment = factComment;
         Place   = factPlace;
         if (factType == NAME)
         {
             Comment = Comment.Replace("/", "");
         }
     }
     Comment = EnhancedTextInfo.ToTitleCase(Comment).Trim();
     if (Properties.GeneralSettings.Default.ReverseLocations)
     {
         Location = FactLocation.GetLocation(ReverseLocation(Place), latitude, longitude, FactLocation.Geocode.NOT_SEARCHED);
     }
     else
     {
         Location = FactLocation.GetLocation(Place, latitude, longitude, FactLocation.Geocode.NOT_SEARCHED);
     }
 }
Пример #8
0
 public void SetCensusReferenceDetails(CensusReference cr, CensusLocation cl, string comment)
 {
     if (!HasValidCensusReference)
     {
         this.CensusReference = cr;
     }
     if (Location.IsBlank)
     {
         Location = cl.Equals(CensusLocation.UNKNOWN) ?
                    FactLocation.GetLocation(cr.Country, Properties.GeneralSettings.Default.AddCreatedLocations) :
                    FactLocation.GetLocation(cl.Location, Properties.GeneralSettings.Default.AddCreatedLocations);
     }
     if (Comment.Length == 0 && comment.Length > 0)
     {
         Comment = comment;
     }
 }
Пример #9
0
        public static int AddLostCousinsFacts()
        {
            int count = 0;

            if (InstanceConnection.State != ConnectionState.Open)
            {
                InstanceConnection.Open();
            }
            using (SqliteCommand cmd = new SqliteCommand("select CensusYear, CensusCountry, CensusRef, IndID, FullName from LostCousins", InstanceConnection))
            {
                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string     indID    = reader["IndID"].ToString();
                        string     fullName = reader["FullName"].ToString();
                        Individual ind      = FamilyTree.Instance.GetIndividual(indID);
                        if (ind?.Name == fullName) // only load if individual exists in this tree.
                        {
                            string CensusYear    = reader["CensusYear"].ToString();
                            string CensusCountry = reader["CensusCountry"].ToString();
                            string CensusRef     = reader["CensusRef"].ToString();
                            if (!ind.IsLostCousinsEntered(CensusDate.GetLostCousinsCensusYear(new FactDate(CensusYear), true)))
                            {
                                FactLocation location = FactLocation.GetLocation(CensusCountry);
                                Fact         f        = new Fact(CensusRef, Fact.LOSTCOUSINS, new FactDate(CensusYear), location, string.Empty, true, true);
                                ind?.AddFact(f);
                            }
                            count++;
                        }
                        else
                        {
                            Console.Write("name wrong");
                            // UpdateFullName(reader, ind.Name); needed during testing
                        }
                    }
                }
            }
            return(count);
        }
Пример #10
0
        public void FactLocationConstructorTest()
        {
            FactLocation.LoadConversions(Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\..\\FTAnalyzer.Shared\\FTAnalyzer.Shared"));
            FactLocation factLocation;

//            factLocation = FactLocation.GetLocation("Aberdeen, Scotland");
//            Assert.IsTrue(factLocation.ToString().Equals("Aberdeen, Aberdeenshire, Scotland"));

            factLocation = FactLocation.GetLocation("America");
            Assert.IsTrue(factLocation.ToString().Equals("United States"));

            // check for default strip empty locations
            FTAnalyzer.Properties.GeneralSettings.Default.AllowEmptyLocations = false;
            factLocation = FactLocation.GetLocation("Parish Church of St Mary, , South Stoneham, Hampshire, ENG");
            Assert.IsTrue(factLocation.ToString().Equals("Parish Church of St Mary, South Stoneham, Hampshire, England"));

            factLocation = FactLocation.GetLocation(", , West End, Hampshire, ENG");
            Assert.IsTrue(factLocation.ToString().Equals("West End, Hampshire, England"));

            factLocation = FactLocation.GetLocation(", Fareham Registration District, , Hampshire, ENG");
            Assert.IsTrue(factLocation.ToString().Equals("Fareham Registration District, Hampshire, England"));

            // check when allowing empty locations
            FTAnalyzer.Properties.GeneralSettings.Default.AllowEmptyLocations = true;
            factLocation = FactLocation.GetLocation("Parish Church of St Mary, , South Stoneham, Hampshire, ENG");
            Assert.IsTrue(factLocation.ToString().Equals("Parish Church of St Mary, , South Stoneham, Hampshire, England"));

            factLocation = FactLocation.GetLocation(", , West End, Hampshire, ENG");
            Assert.IsTrue(factLocation.ToString().Equals("West End, Hampshire, England"));

            factLocation = FactLocation.GetLocation(", Fareham Registration District, , Hampshire, ENG");
            Assert.IsTrue(factLocation.ToString().Equals("Fareham Registration District, , Hampshire, England"));

            factLocation = FactLocation.GetLocation("U.S.A.");
            Assert.IsTrue(factLocation.ToString().Equals("United States"));

            factLocation = FactLocation.GetLocation("4 Old Grey Street, Sunderland, Co Durham");
            Assert.IsTrue(factLocation.ToString().Equals("4 Old Grey Street, Sunderland, County Durham, England"));
        }
Пример #11
0
        private void SetAddress(string factType, XmlNode node)
        {
            XmlNode addr = node.SelectSingleNode("ADDR");

            if (addr == null)
            {
                return;
            }
            string  result = string.Empty; // need to do something with an ADDR tag
            XmlNode ctry   = node.SelectSingleNode("ADDR/CTRY");

            if (ctry != null)
            {
                result = ctry.InnerText;
            }
            XmlNode stae = node.SelectSingleNode("ADDR/STAE");

            if (stae != null)
            {
                result = (result.Length > 0) ? stae.InnerText + ", " + result : stae.InnerText;
            }
            XmlNode city = node.SelectSingleNode("ADDR/CITY");

            if (city != null)
            {
                result = (result.Length > 0) ? city.InnerText + ", " + result : city.InnerText;
            }
            XmlNode adr3 = node.SelectSingleNode("ADDR/ADR3");

            if (adr3 != null)
            {
                result = (result.Length > 0) ? adr3.InnerText + ", " + result : adr3.InnerText;
            }
            XmlNode adr2 = node.SelectSingleNode("ADDR/ADR2");

            if (adr2 != null)
            {
                result = (result.Length > 0) ? adr2.InnerText + ", " + result : adr2.InnerText;
            }
            XmlNode adr1 = node.SelectSingleNode("ADDR/ADR1");

            if (adr1 != null)
            {
                result = (result.Length > 0) ? adr1.InnerText + ", " + result : adr1.InnerText;
            }
            string address = string.Empty;

            if (addr.FirstChild != null && addr.FirstChild.Value != null)
            {
                address = addr.FirstChild.Value;
            }
            XmlNodeList list = node.SelectNodes("ADDR/CONT");

            foreach (XmlNode cont in list)
            {
                if (cont.FirstChild != null && cont.FirstChild.Value != null)
                {
                    address += " " + cont.FirstChild.Value;
                }
            }
            if (address.Length > 0)
            {
                result = (result.Length > 0) ? address + ", " + result : address;
            }
            //   ADDR <ADDRESS_LINE> {1:1} p.41
            //+1 CONT <ADDRESS_LINE> {0:3} p.41
            //+1 ADR1 <ADDRESS_LINE1> {0:1} p.41
            //+1 ADR2 <ADDRESS_LINE2> {0:1} p.41
            //+1 ADR3 <ADDRESS_LINE3> {0:1} p.41
            //+1 CITY <ADDRESS_CITY> {0:1} p.41
            //+1 STAE <ADDRESS_STATE> {0:1} p.42
            //+1 POST <ADDRESS_POSTAL_CODE> {0:1} p.41
            //+1 CTRY <ADDRESS_COUNTRY>

            if (!Fact.COMMENT_FACTS.Contains(factType))
            {
                Location = FactLocation.GetLocation(result);
            }
        }