private GeoDataModel SplitMapData(string data)
        {
            // Split each object per line.
            string[] obj = data.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            // Mapping
            var mapObject = new GeoDataModel();

            foreach (var o in obj)
            {
                if (o.StartsWith("<"))
                {
                    string[] line = o.Split(new[] { "<", "> ", " <>" }, StringSplitOptions.None);
                    MapIdentityAndProjValue(mapObject, line);
                }
                else if (o.StartsWith("# area"))
                {
                    string[] line = o.Split(new[] { "# area: (lat: ", ") - (lon: ", ", ", ") [", "]" }, StringSplitOptions.None);
                    MapAreaLine(mapObject, line);
                }
                else if ((o.StartsWith("# DEPRECATED")) || (o.Contains("# DISCONTINUED")))
                {
                    mapObject.DeprecatedOrDiscontinued = o;
                }
                else
                {
                    MapNameAndDescription(mapObject, o);
                }
            }
            return(mapObject);
        }
 private void MapAreaLine(GeoDataModel mapObject, string[] line)
 {
     mapObject.MinLat          = line[1];
     mapObject.MaxLat          = line[2];
     mapObject.MinLon          = line[3];
     mapObject.MaxLon          = line[4];
     mapObject.AreaDescription = line[5];
 }
        private void MapNameAndDescription(GeoDataModel mapObject, string o)
        {
            var smallerChunks = o.Split(new[] { "# ", " " }, StringSplitOptions.None);

            mapObject.Name = smallerChunks[1];

            var firstIndexOf         = o.IndexOf(' ');
            var secondIndexOf        = o.IndexOf(' ', firstIndexOf + 1);
            var constructDescription = o.Substring(secondIndexOf + 2);

            mapObject.Description = constructDescription.Remove(constructDescription.Length - 1);
        }
Пример #4
0
        public static async Task GetGeoDataFromIP() // link = http://ip-api.com/json/2600:1700:c910:1900::43?fields=regionName,city,district,zip,lat,lon
        {
            var    client     = new HttpClient();
            string externalIp = await client.GetStringAsync("http://icanhazip.com");

            externalIp = externalIp.Replace("\n", "");

            var response = await client.GetStringAsync($"http://ip-api.com/json/{externalIp}?fields=regionName,city,district,zip,lat,lon");

            GeoDataModel infoReturn = JsonConvert.DeserializeObject <GeoDataModel>(response);

            LocalValuesModel.Latitude  = infoReturn.Lat;
            LocalValuesModel.Longitude = infoReturn.Lon;
            LocalValuesModel.City      = infoReturn.City;
            LocalValuesModel.State     = infoReturn.RegionName;
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the GeoDataViewModel class.
        /// </summary>
        public GeoDataViewModel(GeoDataModel model)
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}

            Model = model;
            Model.PropertyChanged += (s, e) =>
            {
                if ( e.PropertyName == GeoDataModel.DatumPropertyName )
                {
                    RaisePropertyChanged(CurrentGeoDatumPropertyName);
                }
                if ( e.PropertyName == GeoDataModel.LocationPropertyName )
                {
                    RaisePropertyChanged(GeoHashPropertyName);
                    RaisePropertyChanged(GeoLocationPropertyName);
                    RaisePropertyChanged(UtmLocationPropertyName);
                    RaisePropertyChanged(MgrsLocationPropertyName);
                    RaisePropertyChanged(L7018FramePropertyName);
                }
                GeoPoint point = new GeoPoint(Model.Location);
                point.Datum = Model.Datum;
                RaisePropertyChanged(GeoPointPropertyName, _oldLocation, point, true);
                _oldLocation = point;
            };

            GeoDatums = new ObservableCollection<GeoDatum>();
            GeoDatums.Add(GeoDatum.DatumWGS84());
            GeoDatums.Add(GeoDatum.DatumIndian1975());
            GeoDatums.Add(GeoDatum.DatumIndian1954());

            L7018Index = new ObservableCollection<RtsdMapFrame>();
            RtsdMapIndex.CalcIndexList();
            foreach (var entry in RtsdMapIndex.MapIndexL7018.OrderBy(x => x.Name))
            {
                L7018Index.Add(entry);
            }

            _oldLocation = new GeoPoint(Model.Location);
            _oldLocation.Datum = Model.Datum;
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the GeoDataViewModel class.
        /// </summary>
        public GeoDataViewModel(GeoDataModel model)
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}

            Model = model;
            Model.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == GeoDataModel.DatumPropertyName)
                {
                    RaisePropertyChanged(CurrentGeoDatumPropertyName);
                }
                if (e.PropertyName == GeoDataModel.LocationPropertyName)
                {
                    RaisePropertyChanged(GeoHashPropertyName);
                    RaisePropertyChanged(GeoLocationPropertyName);
                    RaisePropertyChanged(UtmLocationPropertyName);
                    RaisePropertyChanged(MgrsLocationPropertyName);
                    RaisePropertyChanged(L7018FramePropertyName);
                }
                GeoPoint point = new GeoPoint(Model.Location);
                point.Datum = Model.Datum;
                RaisePropertyChanged(GeoPointPropertyName, _oldLocation, point, true);
                _oldLocation = point;
            };

            GeoDatums = new ObservableCollection <GeoDatum>();
            GeoDatums.Add(GeoDatum.DatumWGS84());
            GeoDatums.Add(GeoDatum.DatumIndian1975());
            GeoDatums.Add(GeoDatum.DatumIndian1954());

            L7018Index = new ObservableCollection <RtsdMapFrame>();
            RtsdMapIndex.CalcIndexList();
            foreach (var entry in RtsdMapIndex.MapIndexL7018.OrderBy(x => x.Name))
            {
                L7018Index.Add(entry);
            }

            _oldLocation       = new GeoPoint(Model.Location);
            _oldLocation.Datum = Model.Datum;
        }
        public void Update_Click(object sender, RoutedEventArgs e)
        {
            GeoDataModel updatedData = (GeoDataModel)GeoDataList.SelectedItem;

            try
            {
                updatedData.PostalCode  = int.Parse(PostalCodeBox.Text);
                updatedData.City        = CityBox.Text;
                updatedData.Population  = int.Parse(PopulationBox.Text);
                updatedData.Temperature = double.Parse(TemperatureBox.Text);
                SQLToolbox.UpdateGeoData(updatedData);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            GeoDataList.Items.Refresh();
        }
        public void Create_Click(object sender, RoutedEventArgs e)
        {
            GeoDataModel geoData = new GeoDataModel();

            try
            {
                geoData.PostalCode  = int.Parse(PostalCodeBox.Text);
                geoData.City        = CityBox.Text;
                geoData.Population  = int.Parse(PopulationBox.Text);
                geoData.Temperature = double.Parse(TemperatureBox.Text);
                SQLToolbox.CreateGeoData(geoData);
                MainViewModel.GeoDataList.Add(SQLToolbox.ReturnIDGeo(geoData));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the GeoDataMapViewModel class.
        /// </summary>
        /// <param name="model">The model with the actual data.</param>
        public GeoDataMapViewModel(GeoDataModel model)
        {
            if ( IsInDesignMode )
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                Messenger.Default.Register<PropertyChangedMessage<GeoPoint>>(this, GeoDataModelPropertyChanged);

                // Code runs "for real": Connect to service, etc...
            }

            Model = model;
            Model.PropertyChanged += (s, e) =>
            {
                if ( e.PropertyName == GeoDataModel.LocationPropertyName )
                {
                    RaisePropertyChanged(PushPinLocationPropertyName);
                }
            };
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the GeoDataMapViewModel class.
        /// </summary>
        /// <param name="model">The model with the actual data.</param>
        public GeoDataMapViewModel(GeoDataModel model)
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                Messenger.Default.Register <PropertyChangedMessage <GeoPoint> >(this, GeoDataModelPropertyChanged);

                // Code runs "for real": Connect to service, etc...
            }

            Model = model;
            Model.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == GeoDataModel.LocationPropertyName)
                {
                    RaisePropertyChanged(PushPinLocationPropertyName);
                }
            };
        }
 private void MapIdentityAndProjValue(GeoDataModel mapObject, string[] line)
 {
     mapObject.Identity  = Convert.ToInt32(line[1]);
     mapObject.ProjValue = line[2];
 }