Example #1
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;
        }
Example #2
0
        private void SetValues(GeoPoint geoPoint, UtmPoint utmPoint, object sender)
        {
            if ( sender != edt_LatLong )
            {
                if ( geoPoint == null )
                {
                    edt_LatLong.Text = String.Empty;
                }
                else
                {
                    edt_LatLong.Text = geoPoint.ToString();
                }
            }
            if ( sender != edt_geohash )
            {
                if ( geoPoint == null )
                {
                    edt_geohash.Text = String.Empty;
                }
                else
                {
                    edt_geohash.Text = geoPoint.GeoHash;
                }
            }
            if ( sender != edt_UTM )
            {
                if ( utmPoint == null )
                {
                    edt_UTM.Text = String.Empty;
                }
                else
                {
                    edt_UTM.Text = utmPoint.ToString();
                }
            }
            if ( sender != edt_MGRS )
            {
                if ( utmPoint == null )
                {
                    edt_MGRS.Text = String.Empty;
                }
                else
                {
                    edt_MGRS.Text = utmPoint.ToMgrsString(6);
                }
            }
            _Point = geoPoint;
            btnFlyTo.Enabled = (_Point != null);

            lbl_L7018Value.Text = "Not available";
            if ( geoPoint != null )
            {
                try
                {
                    var sheet = RtsdMapIndex.IndexL7018(geoPoint);
                    if (sheet != null)
                    {
                        lbl_L7018Value.Text = sheet.Name;
                    }
                }
                catch ( ArgumentOutOfRangeException )
                {
                }
            }
        }