Ejemplo n.º 1
0
        /// <summary>
        /// Converts the specified <paramref name="geometry"/> into a corresponding instance of <see cref="IShape"/>.
        /// </summary>
        /// <param name="geometry">The geometry to be converted.</param>
        /// <returns>An instance of <see cref="IShape"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="geometry"/> is <c>null</c>.</exception>
        /// <exception cref="WktUnsupportedTypeException">type of <paramref name="geometry"/> is not supported.</exception>
        public static IShape ToShape(WktGeometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException(nameof(geometry));
            }

            switch (geometry)
            {
            case WktPolygon polygon:
                return(ToPolygon(polygon));

            case WktMultiPolygon multi:
                return(ToMultiPolygon(multi));

            default:
                throw new WktUnsupportedTypeException(geometry.GetType().FullName);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the area of the specified WKT <paramref name="geometry"/> shape measured in sqaure metres.
        /// </summary>
        /// <param name="geometry">The WKT shape.</param>
        /// <returns>A <see cref="double"/> representing the area of the shape in square metres.</returns>
        /// <remarks>For this method to work, it is assumed that coordinates are specified using the
        /// <strong>WGS 84</strong> coordinate system (eg. used by the Global Positioning System).</remarks>
        /// <see>
        ///     <cref>https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84</cref>
        /// </see>
        /// <see>
        ///     <cref>https://en.wikipedia.org/wiki/Global_Positioning_System</cref>
        /// </see>
        /// <exception cref="ArgumentNullException"><paramref name="geometry"/> is <c>null</c>.</exception>
        public static double GetArea(WktGeometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException(nameof(geometry));
            }

            switch (geometry)
            {
            case WktMultiPolygon multi:
                return(GetArea(multi));

            case WktPolygon polygon:
                return(GetArea(polygon));

            default:
                throw new InvalidOperationException("Unsupported type " + geometry.GetType());
            }
        }