Ejemplo n.º 1
0
        public void PopulateLocationFromGeolocationCache(List <ChargePoint> itemList, CoreReferenceData coreRefData)
        {
            OCM.Import.Analysis.SpatialAnalysis spatialAnalysis = new Analysis.SpatialAnalysis(TempFolder + "\\Shapefiles\\World\\ne_10m_admin_0_map_units.shp");

            //process list of locations, populating country refreshing cache where required
            foreach (var item in itemList)
            {
                if (item.AddressInfo.Country == null && item.AddressInfo.CountryID == null)
                {
                    Country country = null;

                    var test = spatialAnalysis.ClassifyPoint((double)item.AddressInfo.Latitude, (double)item.AddressInfo.Longitude);
                    if (test != null)
                    {
                        country = coreRefData.Countries.FirstOrDefault(c => c.ISOCode == test.CountryCode || c.Title == test.CountryName);
                    }
                    if (country == null)
                    {
                        var geoLookup = geolocationCacheManager.PerformLocationLookup((double)item.AddressInfo.Latitude, (double)item.AddressInfo.Longitude, coreRefData.Countries);
                        if (geoLookup != null)
                        {
                            country = coreRefData.Countries.FirstOrDefault(c => c.ID == geoLookup.CountryID || c.ISOCode == geoLookup.CountryCode || c.Title == geoLookup.CountryName);
                        }
                    }
                    if (country != null)
                    {
                        item.AddressInfo.Country = country;

                        //remove country name from address line 1 if present
                        if (item.AddressInfo.AddressLine1 != null)
                        {
                            if (item.AddressInfo.AddressLine1.ToLower().Contains(country.Title.ToLower()))
                            {
                                item.AddressInfo.AddressLine1 = item.AddressInfo.AddressLine1.Replace(country.Title, "").Trim();
                            }
                        }
                    }

                    if (item.AddressInfo.Country == null)
                    {
                        LogHelper.Log("Failed to resolve country for item:" + item.AddressInfo.Title);
                    }
                    else
                    {
                        item.AddressInfo.CountryID = item.AddressInfo.Country.ID;
                    }
                }
            }

            //cache may have updates, save for next time
            geolocationCacheManager.SaveCache();
        }
Ejemplo n.º 2
0
        public void PopulateLocationFromGeolocationCache(List<ChargePoint> itemList, CoreReferenceData coreRefData)
        {
            OCM.Import.Analysis.SpatialAnalysis spatialAnalysis = new Analysis.SpatialAnalysis(TempFolder + "\\Shapefiles\\World\\ne_10m_admin_0_map_units.shp");

            //process list of locations, populating country refreshing cache where required
            foreach (var item in itemList)
            {
                if (item.AddressInfo.Country == null && item.AddressInfo.CountryID == null)
                {
                    Country country = null;

                    var test = spatialAnalysis.ClassifyPoint((double)item.AddressInfo.Latitude, (double)item.AddressInfo.Longitude);
                    if (test != null)
                    {
                        country = coreRefData.Countries.FirstOrDefault(c => c.ISOCode == test.CountryCode || c.Title == test.CountryName);
                    }
                    if (country == null)
                    {
                        var geoLookup = geolocationCacheManager.PerformLocationLookup((double)item.AddressInfo.Latitude, (double)item.AddressInfo.Longitude, coreRefData.Countries);
                        if (geoLookup != null)
                        {
                            country = coreRefData.Countries.FirstOrDefault(c => c.ID == geoLookup.CountryID || c.ISOCode == geoLookup.CountryCode || c.Title == geoLookup.CountryName);
                        }
                    }
                    if (country != null)
                    {
                        item.AddressInfo.Country = country;

                        //remove country name from address line 1 if present
                        if (item.AddressInfo.AddressLine1 != null)
                        {
                            if (item.AddressInfo.AddressLine1.ToLower().Contains(country.Title.ToLower()))
                            {
                                item.AddressInfo.AddressLine1 = item.AddressInfo.AddressLine1.Replace(country.Title, "").Trim();
                            }
                        }
                    }

                    if (item.AddressInfo.Country == null)
                    {
                        LogHelper.Log("Failed to resolve country for item:" + item.AddressInfo.Title);
                    }
                    else
                    {
                        item.AddressInfo.CountryID = item.AddressInfo.Country.ID;
                    }
                }
            }

            //cache may have updates, save for next time
            geolocationCacheManager.SaveCache();
        }