Beispiel #1
0
        /// <summary>
        /// An address pairs file is simply a tab-delimited list of from/to addresses.
        /// See the tools tab, where this file can be created by random pairing of a sample list of addresses.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="pairList"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        private bool LoadAddressPairsFile(string path, out List <GisFromToPair> pairList, out string explanation)
        {
            pairList    = new List <GisFromToPair>();
            explanation = "";

            try
            {
                textPairsFileContents.Text = path;

                if (!File.Exists(path))
                {
                    OpenFileDialog dialog = new OpenFileDialog();
                    string         folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                    dialog.InitialDirectory = folder;
                    dialog.Filter           = "CSV Files (*.csv)|*.csv";
                    dialog.DefaultExt       = "csv";
                    dialog.FileName         = "SamplePairData.csv";
                    dialog.CheckFileExists  = true;

                    DialogResult result = dialog.ShowDialog();
                    if (result != DialogResult.OK)
                    {
                        return(false);
                    }

                    path = dialog.FileName;
                    textAddressPairsFilepath.Text = path;
                }

                if (!SampleHelper.GetFromTabDelimitedPairFile(path, out pairList, out explanation))
                {
                    explanation = $"Cannot get Pairs. Err={explanation}";
                    return(false);
                }

                StringBuilder sb = new StringBuilder();
                foreach (GisFromToPair pair in pairList)
                {
                    sb.AppendLine(pair.ToString());
                }

                textPairsFileContents.Text = sb.ToString();

                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"File={path} Err={ex}";
                return(false);
            }
        }
Beispiel #2
0
        private void buttonCreatePairFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (GisLocationList == null || !GisLocationList.Any())
                {
                    alert($"A list of locations (addresses) is needed.");
                    return;
                }

                int pairCount = 100;
                if (!SampleHelper.CreatePairedData(GisLocationList, pairCount, out List <GisFromToPair> pairList, out string explanation))
                {
                    alert($"Cannot create {pairCount} pairs. Err={explanation}");
                    return;
                }

                string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                SaveFileDialog dialog = new SaveFileDialog();
                dialog.InitialDirectory = folder;
                dialog.OverwritePrompt  = true;
                dialog.DefaultExt       = "csv";
                dialog.FileName         = "SamplePairData.csv";
                DialogResult result = dialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                string path = dialog.FileName;
                if (!SampleHelper.PutToTabDelimitedPairFile(path, pairList, out explanation))
                {
                    alert($"Could not write pairs to Path={path}");
                }

                alert($"Info: Wrote {pairList.Count} pairs to file={path}");
            }
            catch (Exception ex)
            {
                alert($"Cannot write GIS From-To Pairs. Err={ex.Message}");
            }
        }
Beispiel #3
0
        private void buttonGetJsonFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter           = "json Files (*.json)|*.json";
                dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                dialog.CheckFileExists  = true;

                DialogResult result = dialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                string path = dialog.FileName;

                if (!SampleHelper.GetLocationData(path, out List <GisLocation> locationList, out string explanation))
                {
                    alert($"Cannot get LocationData. Err={explanation}");
                    return;
                }

                StringBuilder sb = new StringBuilder();
                GisLocationList = new List <GisLocation>();
                foreach (GisLocation loc in locationList)
                {
                    GisLocationList.Add(loc);
                    sb.AppendLine(loc.ToString());
                }

                textJsonContents.Text = sb.ToString();
            }
            catch (Exception ex)
            {
                alert($"Cannot get JSON file. Err={ex.Message}");
            }
        }