/// <summary> /// Does objects reverse geocoding. /// </summary> /// <param name="objects">Objects to geocoding.</param> private void _ReverseGeocode(IList <AppData.DataObject> objects) { Debug.Assert(null != objects); // created Debug.Assert(0 < objects.Count); // not empty Debug.Assert(null != _checker); // inited AppGeometry.Envelope extent = App.Current.Map.ImportCheckExtent; int count = objects.Count; for (int index = 0; index < count; ++index) { _checker.ThrowIfCancellationRequested(); if (null == _detectedException) { // NOTE: do if geocoder in valid state IGeocodable geocodable = _GetGeocodable(objects[index]); if (geocodable.GeoLocation.HasValue) { if (extent.IsPointIn(geocodable.GeoLocation.Value)) { // reverse geocode Address geocodedAddress = _ReverseGeocodeSave(geocodable.GeoLocation.Value); if (null != geocodedAddress) { geocodedAddress.CopyTo(geocodable.Address); ++_geocodedCount; } } } } } }
/// <summary> /// Does validate object. /// </summary> /// <param name="obj">Object to validation.</param> private void _ValidateObject(AppData.DataObject obj) { Debug.Assert(null != obj); // created // check geocoded point in map extent var geocodable = obj as IGeocodable; if ((null != geocodable) && geocodable.IsGeocoded) { AppGeometry.Envelope extent = App.Current.Map.ImportCheckExtent; // geolocation is not valide if (!extent.IsPointIn(geocodable.GeoLocation.Value)) { // reset geolocation geocodable.GeoLocation = null; geocodable.Address.MatchMethod = string.Empty; // store problem description string extendedFormat = App.Current.FindString("ImportProcessStatusRecordOutMapExtendFormat"); string errorTextFormat = string.Format(GEOCODE_MESSAGE_FORMAT, _objectsName, extendedFormat); _details.Add(new MessageDetail(MessageType.Warning, errorTextFormat, obj)); } } _StoreValidateResult(obj); }
/// <summary> /// Check is location of geocodable object valid and replace it by candidate from local /// geocoder if exists. /// </summary> /// <param name="geocodable">Geocodable object to check.</param> /// <returns>Is geocodable object valid.</returns> private bool _SourceGeocodedObject(IGeocodable geocodable) { Debug.Assert(null != geocodable); // created bool isObjectGeocoded = false; // First check if name address pair exists in local geocoder database. // If exists - overwrite geolocation and address from it. App currentApp = App.Current; var localGeocoder = new LocalGeocoder(currentApp.Geocoder, currentApp.NameAddressStorage); var nameAddress = new NameAddress(); nameAddress.Name = geocodable.ToString(); nameAddress.Address = geocodable.Address.Clone() as Address; AddressCandidate localCandidate = localGeocoder.Geocode(nameAddress); if (localCandidate == null) { // Update from internal object information. AppGeometry.Envelope extent = currentApp.Map.ImportCheckExtent; if (extent.IsPointIn(geocodable.GeoLocation.Value)) { geocodable.Address.MatchMethod = currentApp.FindString("ImportSourceMatchMethod"); isObjectGeocoded = true; // Full address property must be combined from other fields, because // it is not importing field. if (App.Current.Geocoder.AddressFormat == AddressFormat.MultipleFields) { GeocodeHelpers.SetFullAddress(geocodable.Address); } else { // Do nothing: do not update full address since // it is used for geocoding in Single Address Field Format. } } // Else could not locate object using X/Y attributes - need geocode. } else { // Init from local candidate. // Set location. geocodable.GeoLocation = new AppGeometry.Point(localCandidate.GeoLocation.X, localCandidate.GeoLocation.Y); // Set address. localCandidate.Address.CopyTo(geocodable.Address); isObjectGeocoded = true; } return(isObjectGeocoded); }