Beispiel #1
0
        static void Main(string[] args)
        {
            string apiKey = "648173182770.apps.googleusercontent.com";

            IGeoCoder geoCoder = new GoogleGeoCoder();
            IEnumerable<Address> addresses = geoCoder.GeoCode("26 Bluff St, Salem, NH 03079");

            foreach (var address in addresses)
            {
                Debug.Print(address.Coordinates.Latitude.ToString());
                Debug.Print(address.Coordinates.Longitude.ToString());
            }
        }
    private static void SetLalngByAddress(ImportExportFields writedata, PolinatorInformation polinatorInformation)
    {
        string physicalLocation;
        GoogleGeoCoder geoCoder = new GoogleGeoCoder();
        bool getLocation = false;
        Address[] matchAddress = null;
        int numTry = 0;
        while (!getLocation && numTry < 5)
        {
            try
            {
                numTry++;
                physicalLocation = writedata.LandscapeStreet + " " +
                    writedata.LandscapeZipcode + " " +
                    writedata.LandscapeCity + " " +
                    writedata.LandscapeState + " " +
                    writedata.LandscapeCountry;
                matchAddress = geoCoder.GeoCode(physicalLocation).ToArray();
                getLocation = true;
                break;
            }
            catch (Exception ex)
            {
                System.Threading.Thread.Sleep(2000);
            }

        }
        if (matchAddress != null && matchAddress.Length > 0)
        {
            polinatorInformation.Latitude = (decimal)matchAddress[0].Coordinates.Latitude;
            polinatorInformation.Longitude = (decimal)matchAddress[0].Coordinates.Longitude;
            if (matchAddress.Length > 1)
                polinatorInformation.FuzyLocation = true;

        }
    }
Beispiel #3
0
 public ActionResult GeoCodeTest(string address)
 {
     IGeoCoder coder = new GoogleGeoCoder();
     var res = coder.GeoCode(address);
     return Json(res, JsonRequestBehavior.AllowGet);
 }
    private List<ImportFields> ParseDemoInfo(string filePath, string sDirPath)
    {
        string content = File.ReadAllText(filePath);
        File.Delete(filePath);

        // Parse content
        string[] stringSeparators = new string[] { "\r\n" };
        string[] lines = content.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);

        int numRecord = lines.Length;
        List<ImportFields> listData = new List<ImportFields>();
        List<ImportFields> notConvertList = new List<ImportFields>();
        ImportFields data;
        IGeoCoder geoCoder = new GoogleGeoCoder();

        string nameList = "Tom, Marry, Adinath, Ajitesh, Akshaj, Akshobhya, Ameyatma, Badri, Badrinath, Bhudhav, Chakradev, Chhatrabhuj, Eashan, Eha, Eka, Ekana, Evyavan, Harinarayan, Hemang, Ijay, Indivar, Ish, Jaipal, Jaithra, Kamalakar, Kamalkant, Kamalnath, Lakshmidhar, Lakshmigopal, Lakshmiraman, Liladhar, Lohitaksh, Lohitaksha, Loknath, Lokranjan, Madhuban, Mahakram, Mahatru, Namish, Narahari, Nityanta, Padmanabha, Padmapati, Padmesh, Parmesh, Phanindranath, Pramodan, Rakshan, Ramakaant, Ramashray, Ranganath, Ratannabha, Ratnabhu, Ratnanidhi, Sadabindu, Sadru, Sahishnu, Samarendra, Samarendu, Samarjit, Samavart, Samendu, Saprathas, Satanand, Satkartar, Satveer,Tommy, Denny, Herry, Nate, Yathavan, David, Aadinath, Aaditeya, Zacharry, Aamod, Zuhayr";
        string[] firstnames = nameList.Split(new char[] { '\n', ',' });

        string orgNameList = "Coca, Pollinator, Friendly Farmers, Microsoft, Hobbyist, Beekeeper, Gardener";
        string[] orgNames = orgNameList.Split(new char[] { '\n', ',' });
        int numFirstName = firstnames.Length;
        string physicalLocation;
        Random random = new Random();
        for (int i = 1; i < numRecord; i++)
        {
            data = new ImportFields();
            string[] values = ImportExportUltility.GetCsvRecord(lines[i]);
            if (values.Length > 2)
            {
                physicalLocation = values[1].Replace("See map: Google Maps ", "");
                string[] sAddress = physicalLocation.Split(new char[] { '\n', ',' }, StringSplitOptions.RemoveEmptyEntries);
                int len = sAddress.Length;
                int startDataIndex = 0;
                while (string.IsNullOrWhiteSpace(sAddress[startDataIndex]) && startDataIndex < len)
                {
                    startDataIndex++;
                }
                if (startDataIndex<len)
                    data.LandscapeStreet = sAddress[startDataIndex].Trim();
                if (startDataIndex+1 < len)
                     data.LandscapeZipcode = sAddress[startDataIndex + 1].Trim();
                if (startDataIndex +2< len)
                     data.LandscapeCity = sAddress[startDataIndex + 2].Trim();
                data.LandscapeState = values[2].Trim();
                data.Premium = 1;
                data.PollinatorSize = random.Next(1, 8);
                data.PollinatorType = random.Next(1, 9);
                data.FirstName = firstnames[random.Next(1, numFirstName - 1)];
                data.OrganizationName = orgNames[random.Next(1, 8)];
                data.PhotoUrl = "";//UploadFiles/458586204/Burts Bees logo.png";

                if (IS_GET_LOCATION)
                {
                    //Get location from address
                    physicalLocation = physicalLocation.Replace("\n", "").Trim();

                    geoCoder = new GoogleGeoCoder();
                    bool getLocation = false;
                    Address[] matchAddress = null;
                    int numTry = 0;
                    while (!getLocation && numTry < 5)
                    {
                        try
                        {
                            matchAddress = geoCoder.GeoCode(physicalLocation).ToArray();
                            getLocation = true;
                            numTry++;
                            break;
                        }
                        catch (Exception ex)
                        {
                            System.Threading.Thread.Sleep(2000);
                            //  Pollinator.Common.Logger.Error("Error occured at " + typeof(Admin_DataMigration).Name + "Get location from address. Exception:", ex);
                        }
                    }

                    if (matchAddress != null && matchAddress.Length > 0)
                    {
                        data.Latitude = matchAddress[0].Coordinates.Latitude;
                        data.Longitude = matchAddress[0].Coordinates.Longitude;
                        listData.Add(data);
                    }
                    else
                    {
                        data.LineNumber = (i + 1).ToString();
                        data.PhysicalLocation = physicalLocation;
                        notConvertList.Add(data);
                    }
                }
                else
                {
                    if (i != 29 && i != 53)
                    {
                        listData.Add(data);
                    }
                }
            }
        }

        WriteCsvFile(listData, sDirPath, @"\output.csv");

        if (IS_GET_LOCATION)
        {
            //write file to check error line (can't get location)
            var csv = new StringBuilder();
            string newLine = "LineNumber,PhysicalLocation,OrganizationName,PollinatorSize,PollinatorType, LandscapeCity,LandscapeState,LandscapeZipcode," + Environment.NewLine;
            csv.Append(newLine);
            for (int i = 0; i < notConvertList.Count; i++)
            {
                ImportFields writedata = notConvertList.ElementAt(i);
                newLine = string.Format("{0}, \"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",{8}",
                                writedata.LineNumber,
                                writedata.PhysicalLocation,
                                writedata.OrganizationName,
                                writedata.PollinatorSize,
                                writedata.PollinatorType,
                                writedata.LandscapeCity,
                                writedata.LandscapeState,
                                writedata.LandscapeZipcode,
                                Environment.NewLine);
                csv.Append(newLine);
            }

            File.WriteAllText(sDirPath + @"\output_error.csv", csv.ToString());
        }

        return listData;
    }
    private static List<ImportFields> GetLocationForOldData(List<ImportFields> listdata)
    {
        int numRecord = listdata.Count;
        List<ImportFields> outputList = new List<ImportFields>();
        GoogleGeoCoder geoCoder;
        ImportFields writedata;
        string physicalLocation;
        for (int i = 0; i < numRecord; i++)
        {
            writedata = listdata.ElementAt(i);
            if (!writedata.Longitude.HasValue)
            {
                geoCoder = new GoogleGeoCoder();
                bool getLocation = false;
                Address[] matchAddress = null;
                int numTry = 0;
                while (!getLocation && numTry < 5)
                {
                    try
                    {
                        numTry++;
                        physicalLocation = writedata.LandscapeStreet + " " +
                            writedata.LandscapeZipcode + " " +
                            writedata.LandscapeCity + " " +
                            writedata.LandscapeState + " " +
                            writedata.LandscapeCountry;
                        matchAddress = geoCoder.GeoCode(physicalLocation).ToArray();
                        getLocation = true;
                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Threading.Thread.Sleep(2000);
                        //  Pollinator.Common.Logger.Error("Error occured at " + typeof(Admin_ImportData).Name + "Get location from address. Exception:", ex);
                    }

                }
                if (matchAddress != null && matchAddress.Length > 0)
                {
                    writedata.Latitude = matchAddress[0].Coordinates.Latitude;
                    writedata.Longitude = matchAddress[0].Coordinates.Longitude;
                    if (matchAddress.Length > 1)
                        writedata.FuzyLocation = true;

                }
            }
            outputList.Add(writedata);
        }
        return outputList;
    }
Beispiel #6
0
        static void Main(string[] args)
        {
            // Create a connection and a command
            using (SQLiteConnection cnn = new SQLiteConnection("Data Source=investigations.db3"))
            using (SQLiteCommand cmd = cnn.CreateCommand())
            {
                // Open the connection. If the database doesn't exist,
                // it will be created automatically
                cnn.Open();
                // Create a table in the database
                cmd.CommandText = "CREATE TABLE Address (line VARCHAR(100), house VARCHAR(100), " +
                    "street VARCHAR(100), type VARCHAR(100), direction VARCHAR(100), lat NUMERIC, long NUMERIC)";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "CREATE TABLE Investigation (inNum VARCHAR(100), inDate VARCHAR(100)," +
                    "noticeDate VARCHAR(100), nextInDate VARCHAR(100), expiryDate VARCHAR(100)," +
                    " issue VARCHAR(100), status VARCHAR(100), addressId INTEGER, FOREIGN KEY(addressId)" +
                    " REFERENCES Address(addressId))";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "CREATE TABLE Deficiencies (investigationId INTEGER, " +
                    "location VARCHAR(100), desc VARCHAR(100), status VARCHAR(100), "+
                    "FOREIGN KEY(investigationId) REFERENCES Investigation(investigationId))";
                cmd.ExecuteNonQuery();

                IGeoCoder geoCoder = new GoogleGeoCoder("42");

                int NumDeficienciesRead = 0;

                using (XmlReader reader = XmlReader.Create(new FileStream(@"../../investigation.xml", FileMode.Open)))
                {
                    while (reader.ReadToFollowing("INVESTIGATION")/* && NumDeficienciesRead < 100*/)
                    {
                        ReadInvestigation(reader.ReadSubtree(), cmd, geoCoder);
                        NumDeficienciesRead++;
                        if (NumDeficienciesRead % 100 == 0)
                        {
                            Console.WriteLine(NumDeficienciesRead.ToString());
                        }
                    }

                }

            }
        }
		protected override IGeoCoder CreateGeoCoder()
		{
			geoCoder = new GoogleGeoCoder();
			return geoCoder;
		}
Beispiel #8
0
 private void CreateMarker(string title, CityStateZip csz, string address)
 {
     this.Title = title;
     IGeoCoder geocoder = new GoogleGeoCoder();
     this.GeocodingOutput = geocoder.GeoCode(address, csz.City, csz.State, csz.ZipCode, "").ToList();
 }