private bool IsSamePlace(CartoPlaceData p1, CartoPlaceData p2) { return(String.Compare(p1.Country, p2.Country, true) == 0 && String.Compare(p1.Region, p2.Region, true) == 0 //&& String.Compare(p1.Locality, p2.Locality, true) == 0 && String.Compare(p1.Name, p2.Name, true) == 0); }
public CartoPlaceData ParsePlace(string place) { var p = new CartoPlaceData(); p.Name = place; var index = place.LastIndexOf(','); if (index > 0) { var name = place.Substring(0, index).Trim(); var countryCode = place.Substring(index + 1).Trim(); var country = GeoCountryInfo.ByISO(countryCode); if (country != null) { p.Name = name; p.Country = country.Name; index = name.LastIndexOf(','); if (index > 0) { var area = name.Substring(index + 1).Trim(); name = name.Substring(0, index).Trim(); if (country.HasRegions) { var region = GeoRegionInfo.ByISO(country.ISO2, area); if (region != null) { p.Region = region.RegionName; p.Name = name; } else { p.Locality = area; p.Name = name; } } else { p.Locality = area; p.Name = name; } } } } return(p); }
/// <summary> /// Validates the data that will be used to create or update a place /// </summary> public ValidationServiceResponse <CartoPlaceInfo> ValidatePlace(CartoPlaceData data) { var place = CreateCleanPlaceInfo(data); var response = new ValidationServiceResponse <CartoPlaceInfo>(place); // validate place info if (String.IsNullOrWhiteSpace(place.Name)) { response.AddError("Name", "Place name is missing!"); } // validate political info var political = new GeoPolitical(data); // country is required if (!political.IsCountryValid()) { response.AddError("Country", "Country is missing or invalid!"); } // region is only required if specified if (!political.IsRegionOptionalValid()) { response.AddError("Region", "Region is invalid!"); } // timezone cannot be empty or UTC if (!political.IsTimezoneOptionalButNotUTCValid()) { response.AddError("Timezone", "Timezone is invalid!"); } // TODO: check center/bounds // basic validation return(response); }
private CartoPlaceInfo CreateCleanPlaceInfo(CartoPlaceData data) { data.PlaceType = TextMutate.TrimSafe(data.PlaceType); data.PlaceTags = TextMutate.FixKeywords(data.PlaceTags); data.Timezone = TextMutate.TrimSafe(data.Timezone); data.Country = TextMutate.TrimSafe(data.Country); data.Region = TextMutate.TrimSafe(data.Region); data.Name = TextMutate.TrimSafe(data.Name); data.LocalName = TextMutate.TrimSafe(data.LocalName); data.DisplayAs = TextMutate.TrimSafe(data.DisplayAs); data.Description = TextMutate.TrimSafe(data.Description); data.Address = TextMutate.TrimSafe(data.Address); data.Locality = TextMutate.TrimSafe(data.Locality); data.Postcode = TextMutate.TrimSafe(data.Postcode); data.Subregions = TextMutate.TrimSafe(data.Subregions); data.Sublocalities = TextMutate.TrimSafe(data.Sublocalities); return(new CartoPlaceInfo(data)); }
public CartoPlaceInfo(GoogleLocationResult result) { _raw = result.RawJson; _data = new CartoPlaceData(); _data.PlaceKey = result.PlaceID; _data.GoogleKey = result.PlaceID; _data.PlaceType = result.TypedNameSource; _data.Name = TextMutate.StripAccents(result.ShortName); _data.LocalName = (_data.Name == result.LongName ? "" : result.LongName); _data.DisplayAs = (_data.Name == result.TypedName ? "" : result.TypedName); _data.Description = result.ColloquialArea; //data.Timezone = // TODO: determine timezone _data.Country = result.Country; _data.Region = result.Region; _data.Subregions = ""; if (!String.IsNullOrWhiteSpace(result.Region2)) { _data.Subregions += result.Region2; } if (!String.IsNullOrWhiteSpace(result.Region3)) { _data.Subregions += @" \ " + result.Region3; } if (!String.IsNullOrWhiteSpace(result.Region4)) { _data.Subregions += @" \ " + result.Region4; } if (!String.IsNullOrWhiteSpace(result.Region5)) { _data.Subregions += @" \ " + result.Region5; } var address = $"{result.StreeNumber} {result.Route}"; _data.Address = (String.IsNullOrWhiteSpace(address) ? result.Intersection : address); _data.Postcode = result.PostalCode; /* * _data.Premise = result.Premise; * if (!String.IsNullOrWhiteSpace(result.SubPremise)) _data.Premise += @" \ " + result.SubPremise; */ _data.Locality = result.Locality; _data.Sublocalities = result.SubLocality; _data.CenterLatitude = result.Center.Latitude; _data.CenterLongitude = result.Center.Longitude; _data.NorthLatitude = result.Bounds.NorthWest.Latitude; _data.WestLongitude = result.Bounds.NorthWest.Longitude; _data.SouthLatitude = result.Bounds.SouthEast.Latitude; _data.EastLongitude = result.Bounds.SouthEast.Longitude; // update place type based on current data MapPlaceType(); }
public CartoPlaceInfo(CartoPlaceData data) { _data = data; }
public CartoPlaceFormModel(CartoPlaceInfo place, CartoPlaceData data = null) { Place = place; Data = data ?? place.GetData(); Political = new GeoPolitical(Data); }