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>
 /// Converts the specified Well Known Text <paramref name="point"/> to the corresponding point in the <strong>WGS 84</strong> coordinate system.
 /// </summary>
 /// <param name="point">The Well Known Text point.</param>
 /// <returns>An instance of <see cref="IPoint"/> </returns>
 /// <see>
 ///     <cref>https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84</cref>
 /// </see>
 /// <exception cref="ArgumentNullException"><paramref name="point"/> is <c>null</c>.</exception>
 public static IPoint ToPoint(this WktPoint point)
 {
     if (point == null)
     {
         throw new ArgumentNullException(nameof(point));
     }
     return(new Point(point.Y, point.X));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns the <strong>Well Known Text</strong> string representation of the specified <paramref name="point"/>.
 /// </summary>
 /// <param name="point">The point to be converted.</param>
 /// <param name="formatting">The formatting to be used.</param>
 /// <param name="indentation">The indendatation to be used.</param>
 /// <returns>The point formatted as a <strong>Well Known Text</strong> string.</returns>
 protected string ToString(WktPoint point, WktFormatting formatting, int indentation)
 {
     if (formatting == WktFormatting.Indented)
     {
         throw new NotImplementedException("Indented formatting is currently not supported");
     }
     return(string.Format(CultureInfo.InvariantCulture, "({0} {1})", point.X, point.Y));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance from the specified array of <see cref="IPoint"/> <paramref name="coordinates"/>.
 /// </summary>
 /// <param name="coordinates">The coordinates.</param>
 public WktPolygon(IPoint[][] coordinates)
 {
     if (coordinates == null)
     {
         throw new ArgumentNullException(nameof(coordinates));
     }
     Coordinates = new WktPoint[coordinates.Length][];
     for (int i = 0; i < coordinates.Length; i++)
     {
         Coordinates[i] = new WktPoint[coordinates[i].Length];
         for (int j = 0; j < Coordinates[i].Length; j++)
         {
             Coordinates[i][j] = new WktPoint(coordinates[i][j]);
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Converts the specified two-deimensional array of <paramref name="coordinates"/>.
        /// </summary>
        /// <param name="coordinates">The coordinates to be converted.</param>
        /// <returns>A two-dimensional array of <see cref="WktPoint"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="coordinates"/> is <c>null</c>.</exception>
        public static WktPoint[][] ToWkt(IPoint[][] coordinates)
        {
            if (coordinates == null)
            {
                throw new ArgumentNullException(nameof(coordinates));
            }

            WktPoint[][] temp = new WktPoint[coordinates.Length][];

            for (int i = 0; i < coordinates.Length; i++)
            {
                temp[i] = new WktPoint[coordinates[i].Length];
                for (int j = 0; j < temp[i].Length; j++)
                {
                    temp[i][j] = new WktPoint(coordinates[i][j]);
                }
            }

            return(temp);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new empty polygon.
 /// </summary>
 public WktPolygon()
 {
     Coordinates    = new WktPoint[1][];
     Coordinates[0] = new WktPoint[0];
 }