예제 #1
0
        public void SetEntryAngularFormat(string value)
        {
            string format = value.Trim().ToUpper();

            if (format == "DMS")
            {
                _entryFormat = EnumBearingFormat.eDMS;
            }
            else if (format == "DD")
            {
                _entryFormat = EnumBearingFormat.eDD;
            }
        }
예제 #2
0
        private static string XMLDirectionType(EnumBearingFormat format)
        {
            // These are all the types. Not all of them are mapped.
            //
            // _T("North Azimuth"),_T("South Azimuth"),_T("Polar"),_T("Quadrant")

            if (format == EnumBearingFormat.eQuadrantBearing)
            {
                return("Quadrant");
            }

            return("North Azimuth");
        }
예제 #3
0
        private static string XMLDirectionUnit(EnumBearingFormat format)
        {
            // These are all the types. Other are not required.
            //
            // _T("Radian"),_T("Degree"),_T("DMS"),_T("Gradian"),_T("Gon");

            switch (format)
            {
            case EnumBearingFormat.eNSWE:
                return("DMS");

            case EnumBearingFormat.eQuadrantBearing:
                return("DMS");

            case EnumBearingFormat.eDMS:
                return("DMS");

            case EnumBearingFormat.eDD:
                return("Degree");
            }

            return("Degree");
        }
예제 #4
0
        // We have followed ESRI standard when parsing the string bearing
        //   http://resources.arcgis.com/en/help/main/10.1/index.html#//01m60000003z000000
        //
        public double ParseBearing(string bearingString, out EnumBearingFormat enteredBearingFormat, out bool error)
        {
            error = true;

            bool dmsEntry = BearingFormat == EnumBearingFormat.eDMS;

            enteredBearingFormat = BearingFormat;

            if (bearingString == null)
            {
                return(0.0);
            }

            // Strip unnecessary chars and do basic validation.
            //   NS must be at the beginning
            //   EW must be at the end and had a NS
            //   can't have more then 4 '.' or '-'
            //   can't have any other chars, etc.

            string bearingTrim = "";
            bool   containsNS  = false;
            bool   containsEW  = false;
            bool   containsNum = false;
            bool   containsDec = false;
            Int32  countDash   = 0;

            foreach (char ch in bearingString)
            {
                char upperCh = char.ToUpper(ch);
                if (char.IsNumber(upperCh))
                {
                    if (containsEW)
                    {
                        return(0);
                    }
                    bearingTrim += upperCh;
                    containsNum  = true;
                }
                else if ((upperCh == '.') || (upperCh == '-'))
                {
                    if (!containsNum || containsEW || containsDec || (countDash > 3))
                    {
                        return(0);
                    }
                    bearingTrim += upperCh;

                    if (upperCh == '.')
                    {
                        containsDec = true;
                    }
                    else
                    {
                        countDash++;
                    }
                }
                else if ((upperCh == 'N') || (upperCh == 'S'))
                {
                    if (containsEW || containsNS || containsNum)
                    {
                        return(0);
                    }
                    bearingTrim += upperCh;
                    containsNS   = true;
                }
                else if ((upperCh == 'E') || (upperCh == 'W'))
                {
                    if (containsEW || !containsNS)
                    {
                        return(0);
                    }
                    bearingTrim += upperCh;
                    containsEW   = true;
                }
                else if (upperCh != ' ')
                {
                    return(0);
                }
            }
            if (containsNS && !containsEW)
            {
                return(0);
            }

            Int32 strLength = bearingTrim.Length;

            if (strLength == 0)
            {
                return(0);
            }

            // check for NS/EW (and remove NWEW chars)
            Int32 quadrant = 0;

            if (containsNS) // and containsEW (checked above)
            {
                dmsEntry = true;

                Int32 e = strLength - 1;
                if (bearingTrim[0] == 'N')
                {
                    if (bearingTrim[e] == 'W')
                    {
                        quadrant = 4;
                    }
                    else // East
                    {
                        quadrant = 1;
                    }
                }
                else // South
                {
                    if (bearingTrim[e] == 'W')
                    {
                        quadrant = 3;
                    }
                    else // East
                    {
                        quadrant = 2;
                    }
                }
                string withoutNSEW = bearingTrim.Substring(1, strLength - 2);
                bearingTrim = "";

                enteredBearingFormat = EnumBearingFormat.eNSWE;

                // Simplify string from 89-59-59.88 to 89.595988
                bool firstDecFound = false;
                foreach (char ch in withoutNSEW)
                {
                    bool seperator = (ch == '.') || (ch == '-');
                    if (!firstDecFound && seperator)
                    {
                        bearingTrim  += '.';
                        firstDecFound = true;
                    }
                    else if (!seperator)
                    {
                        bearingTrim += ch;
                    }
                }
            }
            bool containsDash = bearingTrim.Contains("-"); // is this a quadrant bearing string.
            bool containsDot  = bearingTrim.Contains("."); // is this a DMS bearing string.

            string[] parts     = bearingTrim.Split('-');
            Int32    partCount = parts.Count();

            if (partCount < 1)
            {
                return(0);
            }
            if (containsDash) // strip out quadrant
            {
                dmsEntry = true;

                if (partCount < 2)
                {
                    return(0);
                }
                Int32.TryParse(parts[partCount - 1], out quadrant);
                partCount--;
                if ((quadrant < 1) || (quadrant > 4))
                {
                    return(0);
                }

                // Simplify string from 89-59-59.88 to 89.595988
                string simplifiedString = parts[0];
                if (partCount > 1)
                {
                    simplifiedString += ".";
                    for (Int32 i = 1; i < partCount; i++)
                    {
                        string subPart = "";
                        foreach (char ch in parts[i])
                        {
                            if (ch != '.')
                            {
                                subPart += ch;
                            }
                        }
                        if ((i <= 2) && (subPart.Length < 2))  // min and sec need to be expressed as two digits.
                        {
                            subPart = subPart.PadLeft(2, '0'); // this fixes a number like 5-47-0-4 to be expressed
                        }
                        simplifiedString += subPart;           // as 5.4700 (not 5.470)
                    }
                }
                bearingTrim = simplifiedString;

                enteredBearingFormat = EnumBearingFormat.eQuadrantBearing;
            }

            parts     = bearingTrim.Split('.');
            partCount = parts.Count();
            if (partCount > 2)
            {
                return(0);
            }

            double ddVal;

            double.TryParse(parts[0], out ddVal);
            if (partCount == 1)  // D
            {
            }
            else if (partCount == 2)
            {
                if (!dmsEntry)   // DD
                {
                    double.TryParse(bearingTrim, out ddVal);
                }
                else             // DMS
                {
                    Int32  mins, secs, secsPlus;
                    string minStr = parts[1].Substring(0, 2);
                    Int32.TryParse(minStr, out mins);
                    ddVal += mins / 60.0;

                    string secStr = parts[1].Substring(2, 2);
                    if ((secStr != null) && (secStr != ""))
                    {
                        Int32.TryParse(secStr, out secs);
                        ddVal += (secs / 3600.0);

                        string secPlusStr = parts[1].Substring(4);
                        if ((secPlusStr != null) && (secPlusStr != ""))
                        {
                            Int32.TryParse(secPlusStr, out secsPlus);
                            ddVal += (secsPlus / 1000000.0);
                        }
                    }
                }
            }

            if (quadrant == 0)
            {
                error = (ddVal < 0) || (ddVal >= 360);
            }
            else
            {
                error = (ddVal < 0) || (ddVal > 90);
            }

            // Now add the quadrant to the value.
            double retVal = ddVal; // this is also the same for quadrant 1

            if (quadrant == 2)
            {
                retVal = 180 - ddVal;
            }
            else if (quadrant == 3)
            {
                retVal = 180 + ddVal;
            }
            else if (quadrant == 4)
            {
                retVal = 360 - ddVal;
            }

            return(retVal);
        }
예제 #5
0
        public string ParseBearing(double bearing, EnumBearingFormat enteredBearingFormat)
        {
            if (double.IsNaN(bearing))
            {
                return("");
            }

            if (enteredBearingFormat == EnumBearingFormat.eUnknown)
            {
                return(bearing.ToString(_precision));
            }

            if (enteredBearingFormat == EnumBearingFormat.eDD)
            {
                return(bearing.ToString(_precision));
            }

            bool displayAsNSWE = ((enteredBearingFormat == EnumBearingFormat.eNSWE) ||
                                  (enteredBearingFormat == EnumBearingFormat.eQuadrantBearing));
            Int32 quadrant = 0;

            if (displayAsNSWE)
            {
                if (bearing < 90)
                {
                    quadrant = 1;
                }
                else if (bearing < 180)
                {
                    bearing  = 180 - bearing;
                    quadrant = 2;
                }
                else if (bearing < 270)
                {
                    bearing -= 180;
                    quadrant = 3;
                }
                else if (bearing < 360)
                {
                    bearing  = 360 - bearing;
                    quadrant = 4;
                }
            }

            // Convert degree to DMS

            Int32  degree     = (Int32)bearing;
            double dMinute    = Math.Abs((bearing - degree) * 60.0); // Sure that the remainder of the digits are +ve
            Int32  minute     = (Int32)dMinute;
            double dSecond    = (dMinute - minute) * 60.0;
            Int32  second     = (Int32)dSecond;
            double dDecSecond = (dSecond - second);

            // Round seconds/minutes/degree based decimal seconds

            if (dDecSecond > 0.5)
            {
                if (second < 59)
                {
                    second++;
                }
                else
                {
                    second = 0;
                    if (minute < 59)
                    {
                        minute++;
                    }
                    else
                    {
                        minute = 0;
                        if (quadrant == 0)
                        {
                            if (degree < 359)
                            {
                                degree++;
                            }
                            else
                            {
                                degree = 0;
                            }
                        }
                        else
                        {
                            if (degree < 89)
                            {
                                degree++;
                            }
                            else
                            {
                                degree = 0;
                            }
                        }
                    }
                }
            }

            // since we strip the degree from its other parts, the -ve value is lost when the value is zero.
            string sDeg = (bearing < 0) && (degree == 0) ? "-" + degree.ToString() : degree.ToString();
            string sMin = minute.ToString().PadLeft(2, '0');
            string sSec = second.ToString().PadLeft(2, '0'); // Add sDecSecond is we need more precision

            switch (quadrant)
            {
            case 1: return("N" + sDeg + "." + sMin + sSec + "E");

            case 2: return("S" + sDeg + "." + sMin + sSec + "E");

            case 3: return("S" + sDeg + "." + sMin + sSec + "W");

            case 4: return("N" + sDeg + "." + sMin + sSec + "W");
            }

            return(sDeg + "." + sMin + sSec);
        }
예제 #6
0
        public string ParseBearing(double bearing, EnumBearingFormat enteredBearingFormat)
        {
            if (double.IsNaN(bearing))
            return "";

              if (enteredBearingFormat == EnumBearingFormat.eUnknown)
              {
            return bearing.ToString(_precision);
              }

              if (enteredBearingFormat == EnumBearingFormat.eDD)
              {
            return bearing.ToString(_precision);
              }

              bool displayAsNSWE = ((enteredBearingFormat == EnumBearingFormat.eNSWE) ||
                            (enteredBearingFormat == EnumBearingFormat.eQuadrantBearing));
              Int32 quadrant = 0;
              if (displayAsNSWE)
              {
            if (bearing < 90)
            {
              quadrant = 1;
            }
            else if (bearing < 180)
            {
              bearing = 180-bearing;
              quadrant =  2;
            }
            else if (bearing < 270)
            {
              bearing -= 180;
              quadrant = 3;
            }
            else if (bearing < 360)
            {
              bearing = 360-bearing;
              quadrant = 4;
            }
              }

              // Convert degree to DMS

              Int32 degree = (Int32)bearing;
              double dMinute = Math.Abs((bearing - degree) * 60.0);  // Sure that the remainder of the digits are +ve
              Int32 minute = (Int32)dMinute;
              double dSecond = (dMinute - minute) * 60.0;
              Int32 second = (Int32)dSecond;
              double dDecSecond = (dSecond - second);

              // Round seconds/minutes/degree based decimal seconds

              if (dDecSecond > 0.5)
              {
            if (second < 59)
              second++;
            else
            {
              second = 0;
              if (minute < 59)
            minute++;
              else
              {
            minute = 0;
            if (quadrant == 0)
            {
              if (degree < 359)
                degree++;
              else
                degree = 0;
            }
            else
            {
              if (degree < 89)
                degree++;
              else
                degree = 0;
            }
              }
            }
              }

              // since we strip the degree from its other parts, the -ve value is lost when the value is zero.
              string sDeg = (bearing < 0) && (degree == 0) ? "-" + degree.ToString() : degree.ToString();
              string sMin = minute.ToString().PadLeft(2, '0');
              string sSec = second.ToString().PadLeft(2, '0');  // Add sDecSecond is we need more precision

              switch (quadrant)
              {
            case 1: return "N" + sDeg + "." + sMin + sSec + "E";
            case 2: return "S" + sDeg + "." + sMin + sSec + "E";
            case 3: return "S" + sDeg + "." + sMin + sSec + "W";
            case 4: return "N" + sDeg + "." + sMin + sSec + "W";
              }

              return sDeg + "." + sMin + sSec;
        }
예제 #7
0
        // We have followed ESRI standard when parsing the string bearing
        //   http://resources.arcgis.com/en/help/main/10.1/index.html#//01m60000003z000000
        //
        public double ParseBearing(string bearingString, out EnumBearingFormat enteredBearingFormat, out bool error)
        {
            error = true;

              bool dmsEntry = BearingFormat == EnumBearingFormat.eDMS;
              enteredBearingFormat = BearingFormat;

              if (bearingString == null)
            return 0.0;

              // Strip unnecessary chars and do basic validation.
              //   NS must be at the beginning
              //   EW must be at the end and had a NS
              //   can't have more then 4 '.' or '-'
              //   can't have any other chars, etc.

              string bearingTrim = "";
              bool containsNS = false;
              bool containsEW = false;
              bool containsNum = false;
              bool containsDec = false;
              Int32 countDash = 0;
              foreach (char ch in bearingString)
              {
            char upperCh = char.ToUpper(ch);
            if (char.IsNumber(upperCh))
            {
              if (containsEW)
            return 0;
              bearingTrim += upperCh;
              containsNum = true;
            }
            else if ((upperCh == '.') || (upperCh == '-'))
            {
              if (!containsNum || containsEW || containsDec || (countDash > 3))
            return 0;
              bearingTrim += upperCh;

              if (upperCh == '.')
            containsDec = true;
              else
            countDash++;
            }
            else if ((upperCh == 'N') || (upperCh == 'S'))
            {
              if (containsEW || containsNS || containsNum)
            return 0;
              bearingTrim += upperCh;
              containsNS = true;
            }
            else if ((upperCh == 'E') || (upperCh == 'W'))
            {
              if (containsEW || !containsNS)
            return 0;
              bearingTrim += upperCh;
              containsEW = true;
            }
            else if (upperCh != ' ')
              return 0;
              }
              if (containsNS && !containsEW)
            return 0;

              Int32 strLength = bearingTrim.Length;
              if (strLength == 0)
            return 0;

              // check for NS/EW (and remove NWEW chars)
              Int32 quadrant = 0;
              if (containsNS) // and containsEW (checked above)
              {
            dmsEntry = true;

            Int32 e = strLength - 1;
            if (bearingTrim[0] == 'N')
            {
              if (bearingTrim[e] == 'W')
            quadrant = 4;
              else // East
            quadrant = 1;
            }
            else // South
            {
              if (bearingTrim[e] == 'W')
            quadrant = 3;
              else // East
            quadrant = 2;
            }
            string withoutNSEW = bearingTrim.Substring(1, strLength - 2);
            bearingTrim = "";

            enteredBearingFormat = EnumBearingFormat.eNSWE;

            // Simplify string from 89-59-59.88 to 89.595988
            bool firstDecFound = false;
            foreach (char ch in withoutNSEW)
            {
              bool seperator = (ch == '.') || (ch == '-');
              if (!firstDecFound && seperator)
              {
            bearingTrim += '.';
            firstDecFound = true;
              }
              else if (!seperator)
            bearingTrim += ch;
            }
              }
              bool containsDash = bearingTrim.Contains("-"); // is this a quadrant bearing string.
              bool containsDot = bearingTrim.Contains(".");  // is this a DMS bearing string.

              string[] parts = bearingTrim.Split('-');
              Int32 partCount = parts.Count();
              if (partCount < 1)
            return 0;
              if (containsDash) // strip out quadrant
              {
            dmsEntry = true;

            if (partCount < 2)
              return 0;
            Int32.TryParse(parts[partCount - 1], out quadrant);
            partCount--;
            if ((quadrant < 1) || (quadrant > 4))
              return 0;

            // Simplify string from 89-59-59.88 to 89.595988
            string simplifiedString = parts[0];
            if (partCount > 1)
            {
              simplifiedString += ".";
              for (Int32 i = 1; i < partCount; i++)
              {
            string subPart = "";
            foreach (char ch in parts[i])
              if (ch != '.')
                subPart += ch;
            if ((i <= 2) && (subPart.Length < 2))   // min and sec need to be expressed as two digits.
              subPart = subPart.PadLeft(2, '0');    // this fixes a number like 5-47-0-4 to be expressed
            simplifiedString += subPart;            // as 5.4700 (not 5.470)
              }
            }
            bearingTrim = simplifiedString;

            enteredBearingFormat = EnumBearingFormat.eQuadrantBearing;
              }

              parts = bearingTrim.Split('.');
              partCount = parts.Count();
              if (partCount > 2)
            return 0;

              double ddVal;
              double.TryParse(parts[0], out ddVal);
              if (partCount == 1)        // D
              {
              }
              else if (partCount == 2)
              {
            if (!dmsEntry)           // DD
            {
              double.TryParse(bearingTrim, out ddVal);
            }
            else                     // DMS
            {
              Int32 mins, secs, secsPlus;
              string minStr = parts[1].Substring(0, 2);
              Int32.TryParse(minStr, out mins);
              ddVal += mins / 60.0;

              string secStr = parts[1].Substring(2, 2);
              if ((secStr != null) && (secStr != ""))
              {
            Int32.TryParse(secStr, out secs);
            ddVal += (secs / 3600.0);

            string secPlusStr = parts[1].Substring(4);
            if ((secPlusStr != null) && (secPlusStr != ""))
            {
              Int32.TryParse(secPlusStr, out secsPlus);
              ddVal += (secsPlus / 1000000.0);
            }
              }
            }
              }

              if (quadrant == 0)
            error = (ddVal < 0) || (ddVal >= 360);
              else
            error = (ddVal < 0) || (ddVal > 90);

              // Now add the quadrant to the value.
              double retVal = ddVal; // this is also the same for quadrant 1
              if (quadrant == 2)
            retVal = 180 - ddVal;
              else if (quadrant == 3)
            retVal = 180 + ddVal;
              else if (quadrant == 4)
            retVal = 360 - ddVal;

              return retVal;
        }
예제 #8
0
        private static string XMLDirectionUnit(EnumBearingFormat format)
        {
            // These are all the types. Other are not required.
              //
              // _T("Radian"),_T("Degree"),_T("DMS"),_T("Gradian"),_T("Gon");

              switch (format)
              {
            case EnumBearingFormat.eNSWE:
              return "DMS";
            case EnumBearingFormat.eQuadrantBearing:
              return "DMS";
            case EnumBearingFormat.eDMS:
              return "DMS";
            case EnumBearingFormat.eDD:
              return "Degree";
              }

              return "Degree";
        }
예제 #9
0
        private static string XMLDirectionType(EnumBearingFormat format)
        {
            // These are all the types. Not all of them are mapped.
              //
              // _T("North Azimuth"),_T("South Azimuth"),_T("Polar"),_T("Quadrant")

              if (format == EnumBearingFormat.eQuadrantBearing)
            return "Quadrant";

              return "North Azimuth";
        }
예제 #10
0
 public void SetEntryAngularFormat(string value)
 {
     string format = value.Trim().ToUpper();
       if (format == "DMS")
     _entryFormat = EnumBearingFormat.eDMS;
       else if (format == "DD")
     _entryFormat = EnumBearingFormat.eDD;
 }