Exemplo n.º 1
0
        /// <summary>
        /// Parses the specified <paramref name="input"/> string into an instance of <see cref="WktGeometry"/>.
        /// </summary>
        /// <param name="input">The input string to parse.</param>
        /// <returns>An instance of <see cref="WktGeometry"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="input"/> is <c>null</c>.</exception>
        /// <exception cref="WktInvalidFormatException"><paramref name="input"/> is not in a known format.</exception>
        /// <exception cref="WktUnsupportedTypeException">type of <paramref name="input"/> is not supported.</exception>
        public static WktGeometry Parse(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentNullException(nameof(input));
            }

            string type = input.Split('(')[0].ToUpper().Trim();

            if (string.IsNullOrWhiteSpace(type))
            {
                throw new WktInvalidFormatException(input);
            }

            switch (type)
            {
            case "POINT": return(WktPoint.Parse(input));

            case "POLYGON": return(WktPolygon.Parse(input));

            case "LINESTRING": return(WktLineString.Parse(input));

            case "MULTIPOINT": return(WktMultiPoint.Parse(input));

            case "MULTILINESTRING": return(WktMultiLineString.Parse(input));

            case "MULTIPOLYGON": return(WktMultiPolygon.Parse(input));

            default: throw new WktUnsupportedTypeException(type);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the <strong>Well Known Text</strong> string representation of the specified <paramref name="lineString"/>.
 /// </summary>
 /// <param name="lineString">The line string to be converted.</param>
 /// <param name="formatting">The formatting to be used.</param>
 /// <param name="indentation">The indendatation to be used.</param>
 /// <returns>The line string formatted as a <strong>Well Known Text</strong> string.</returns>
 protected string ToString(WktLineString lineString, WktFormatting formatting, int indentation)
 {
     if (formatting == WktFormatting.Indented)
     {
         throw new NotImplementedException("Indented formatting is currently not supported");
     }
     return("(" + string.Join(formatting == WktFormatting.Indented ? "," : ", ", from point in lineString select string.Format(CultureInfo.InvariantCulture, "{0} {1}", point.X, point.Y)) + ")");
 }