示例#1
0
 private void edit_MGRS_TextChanged(object sender, EventArgs e)
 {
     if (!_Changing)
     {
         String   value    = TambonHelper.ReplaceThaiNumerals(edt_MGRS.Text.ToUpper()).Trim();
         GeoPoint geoPoint = null;
         UtmPoint utmPoint = null;
         try
         {
             _Changing = true;
             if (!TambonHelper.IsNumeric(value.Substring(0, 2)))
             {
                 value = ZoneForThailandMgrs(value) + value;
             }
             utmPoint       = UtmPoint.ParseMgrsString(value);
             geoPoint       = new GeoPoint(utmPoint, (GeoDatum)cbx_datum.SelectedItem);
             geoPoint.Datum = GeoDatum.DatumWGS84();
         }
         catch
         {
             // invalid string
             utmPoint = null;
             geoPoint = null;
         }
         SetValues(geoPoint, utmPoint, sender);
         _Changing = false;
     }
 }
示例#2
0
        private void btnMonths_Click(object sender, EventArgs e)
        {
            StringBuilder value = new StringBuilder(boxText.Text);

            foreach (KeyValuePair <String, Byte> monthNameThai in TambonHelper.ThaiMonthNames)
            {
                DateTime month          = new DateTime(2000, monthNameThai.Value, 1);
                String   monthNameLocal = month.ToString("MMMM");
                value = value.Replace(monthNameThai.Key, monthNameLocal);
            }
            foreach (KeyValuePair <String, Byte> monthAbbreviation in TambonHelper.ThaiMonthAbbreviations)
            {
                DateTime month          = new DateTime(2000, monthAbbreviation.Value, 1);
                String   monthNameLocal = month.ToString("MMMM");
                value = value.Replace(monthAbbreviation.Key, monthNameLocal);
            }


            foreach (var subString in value.ToString().Split(new String[] { " ", Environment.NewLine, "\t" }, StringSplitOptions.None))
            {
                if (TambonHelper.IsNumeric(subString))
                {
                    Int64 number = Convert.ToInt64(subString);
                    if ((number > 2400) && (number < 2600))
                    {
                        number -= 543;
                        value.Replace(subString, number.ToString());
                    }
                }
            }

            boxText.Text = value.ToString();
        }
示例#3
0
        private void AppendNameInfo(StringBuilder iBuilder)
        {
            iBuilder.AppendLine("Name equal: " + SuffixFrequency(String.Empty).ToString() + " times");
            List <String> lStandardSuffices = new List <String>()
            {
                "เหนือ", "ใต้", "พัฒนา", "ใหม่", "ทอง", "น้อย", "ใน"
            };

            foreach (String lSuffix in lStandardSuffices)
            {
                iBuilder.AppendLine("Suffix " + lSuffix + ": " + SuffixFrequency(lSuffix).ToString() + " times");
            }
            iBuilder.AppendLine("Suffix with number:" + SuffixFrequencyNumbers().ToString() + " times");

            List <String> lStandardPrefixes = new List <String>()
            {
                "ใหม่"
            };

            foreach (String lPrefix in lStandardPrefixes)
            {
                iBuilder.AppendLine("Prefix " + lPrefix + ": " + PrefixFrequency(lPrefix).ToString() + " times");
            }

            iBuilder.AppendLine();

            iBuilder.Append("Other suffices: ");
            List <KeyValuePair <String, Int32> > lSortedSuffices = new List <KeyValuePair <String, Int32> >();

            foreach (KeyValuePair <String, Int32> lKeyValuePair in mNewNameSuffix)
            {
                String lName = TambonHelper.ReplaceThaiNumerals(lKeyValuePair.Key);
                if (lStandardSuffices.Contains(lName))
                {
                }
                else if (String.IsNullOrEmpty(lKeyValuePair.Key))
                {
                }
                else if (TambonHelper.IsNumeric(lName))
                {
                }
                else
                {
                    lSortedSuffices.Add(lKeyValuePair);
                }
            }
            lSortedSuffices.Sort(delegate(KeyValuePair <String, Int32> x, KeyValuePair <String, Int32> y)
            {
                return(y.Value.CompareTo(x.Value));
            });
            foreach (KeyValuePair <String, Int32> lKeyValuePair in lSortedSuffices)
            {
                iBuilder.Append(lKeyValuePair.Key + " (" + lKeyValuePair.Value.ToString() + ") ");
            }
            iBuilder.AppendLine();
        }
示例#4
0
        protected Int32 SuffixFrequencyNumbers()
        {
            Int32 retval = 0;

            foreach (KeyValuePair <String, Int32> lKeyValue in mNewNameSuffix)
            {
                String lName = TambonHelper.ReplaceThaiNumerals(lKeyValue.Key);
                if ((!String.IsNullOrEmpty(lName)) && (TambonHelper.IsNumeric(lName)))
                {
                    retval = retval + lKeyValue.Value;
                }
            }
            return(retval);
        }
示例#5
0
        public PopulationDataEntry Parse(StreamReader reader)
        {
            // Column 1 : is number, then use
            // Column 2 : Amphoe name
            // Column 3 : Tambon name
            // Column 4 : Code
            // Column 5 : Name
            // Column 6 : Muban number
            // Column 7 : Location source/placemark
            // Column 8 : Location UTM Easting (47N, Indian 1974)
            // Column 9 : Location UTM Northing (47N, Indian 1974)

            String currentLine = String.Empty;
            PopulationDataEntry currentChangwat = new PopulationDataEntry();
            PopulationDataEntry currentAmphoe   = new PopulationDataEntry();
            PopulationDataEntry currentTambon   = new PopulationDataEntry();

            while ((currentLine = reader.ReadLine()) != null)
            {
                var subStrings = currentLine.Split(new Char[] { '\t' });
                if ((subStrings.Length > 0) & (!String.IsNullOrEmpty(subStrings[0])) & TambonHelper.IsNumeric(subStrings[0]))
                {
                    PopulationDataEntry currentMuban = new PopulationDataEntry();
                    String amphoe  = subStrings[1].Replace('"', ' ').Trim();
                    String tambon  = subStrings[2].Replace('"', ' ').Trim();
                    String geocode = subStrings[3].Replace('"', ' ').Replace(" ", "").Trim();
                    currentMuban.Geocode = Convert.ToInt32(geocode);
                    currentMuban.Name    = subStrings[4].Replace('"', ' ').Trim();
                    currentMuban.Type    = EntityType.Muban;
                    String comment  = subStrings[6].Replace('"', ' ').Trim();
                    String easting  = subStrings[7].Replace('"', ' ').Replace('E', ' ').Trim();
                    String northing = subStrings[8].Replace('"', ' ').Replace('N', ' ').Trim();
                    if (TambonHelper.IsNumeric(easting) && TambonHelper.IsNumeric(northing))
                    {
                        EntityOffice office = new EntityOffice();
                        office.Type = OfficeType.VillageHeadmanOffice;
                        UtmPoint utmLocation = new UtmPoint(Convert.ToInt32(easting), Convert.ToInt32(northing), 47, true);
                        office.Location       = new GeoPoint(utmLocation, GeoDatum.DatumIndian1975());
                        office.Location.Datum = GeoDatum.DatumWGS84();
                        currentMuban.Offices.Add(office);
                    }
                    String mubanString = subStrings[5].Replace('"', ' ').Trim();
                    if (TambonHelper.IsNumeric(mubanString))
                    {
                        Int32 muban = Convert.ToInt32(mubanString);
                        if (muban != (currentMuban.Geocode % 100))
                        {
                            comment = comment + Environment.NewLine + "Code is " + currentMuban.Geocode.ToString() + ',';
                            comment = comment + " Muban number is " + muban.ToString();
                            currentMuban.Geocode = currentMuban.Geocode - (currentMuban.Geocode % 100) + muban;
                        }
                    }
                    if ((currentMuban.Geocode / 10000) != currentAmphoe.Geocode)
                    {
                        currentAmphoe         = new PopulationDataEntry();
                        currentAmphoe.Name    = tambon;
                        currentAmphoe.Type    = EntityType.Amphoe;
                        currentAmphoe.Geocode = (currentMuban.Geocode / 10000);
                        currentChangwat.SubEntities.Add(currentAmphoe);
                    }
                    if ((currentMuban.Geocode / 100) != currentTambon.Geocode)
                    {
                        currentTambon         = new PopulationDataEntry();
                        currentTambon.Name    = tambon;
                        currentTambon.Type    = EntityType.Tambon;
                        currentTambon.Geocode = (currentMuban.Geocode / 100);
                        currentAmphoe.SubEntities.Add(currentTambon);
                    }
                    currentMuban.Comment = comment;
                    currentTambon.SubEntities.Add(currentMuban);
                }
            }
            currentChangwat.Type = EntityType.Changwat;
            return(currentChangwat);
        }