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);
            }
        }