/// <summary>
        /// Convert a multi polygon from one coordinate system to
        /// another coordinate system.
        /// </summary>
        /// <param name="multiPolygon">Multi polygon that should be converted.</param>
        /// <param name="fromCoordinateSystem">From coordinate system.</param>
        /// <param name="toCoordinateSystem">To coordinate system.</param>
        /// <returns>Multi polygon with coordinates according to toCoordinateSystem</returns>
        public virtual WebMultiPolygon GetConvertedMultiPolygon(WebMultiPolygon multiPolygon,
                                                                WebCoordinateSystem fromCoordinateSystem,
                                                                WebCoordinateSystem toCoordinateSystem)
        {
            Int32             polygonIndex, toPolygonIndex;
            WebMultiPolygon   toMultiPolygon;
            List <WebPolygon> fromPolygons, toPolygons;

            toMultiPolygon = null;
            if (multiPolygon.IsNotNull())
            {
                fromPolygons = new List <WebPolygon>();
                for (polygonIndex = 0; polygonIndex < multiPolygon.Polygons.Count; polygonIndex++)
                {
                    fromPolygons.Add(multiPolygon.Polygons[polygonIndex]);
                }
                toPolygons              = GetConvertedPolygons(fromPolygons, fromCoordinateSystem, toCoordinateSystem);
                toPolygonIndex          = 0;
                toMultiPolygon          = new WebMultiPolygon();
                toMultiPolygon.Polygons = new List <WebPolygon>();
                for (polygonIndex = 0; polygonIndex < multiPolygon.Polygons.Count; polygonIndex++)
                {
                    toMultiPolygon.Polygons.Add(toPolygons[toPolygonIndex]);
                    toPolygonIndex++;
                }
            }

            return(toMultiPolygon);
        }
Example #2
0
        /// <summary>
        /// Get WebMultiPolygon as a string.
        /// </summary>
        /// <param name="multiPolygon">This multi polygon.</param>
        /// <returns>WebMultiPolygon as a string</returns>
        public static String WebToString(this WebMultiPolygon multiPolygon)
        {
            Boolean       isFirstLinearRing, isFirstPolygon;
            StringBuilder wkt;

            wkt = new StringBuilder();

            if (multiPolygon.IsNotNull())
            {
                wkt.Append("MULTIPOLYGON()");
                if (multiPolygon.Polygons.IsNotEmpty())
                {
                    isFirstPolygon = true;
                    foreach (WebPolygon polygon in multiPolygon.Polygons)
                    {
                        if (polygon.LinearRings.IsNotEmpty())
                        {
                            if (isFirstPolygon)
                            {
                                isFirstPolygon = false;
                                wkt.Insert(13, "()");
                            }
                            else
                            {
                                wkt.Insert(13, "(), ");
                            }

                            isFirstLinearRing = true;
                            foreach (WebLinearRing linearRing in polygon.LinearRings)
                            {
                                if (linearRing.Points.IsNotEmpty())
                                {
                                    if (isFirstLinearRing)
                                    {
                                        isFirstLinearRing = false;
                                        wkt.Insert(14, "()");
                                    }
                                    else
                                    {
                                        wkt.Insert(14, "(), ");
                                    }

                                    String komma = String.Empty;

                                    foreach (WebPoint point in linearRing.Points)
                                    {
                                        wkt.Insert(
                                            15,
                                            point.X.WebToStringR().Replace(",", ".") + " "
                                            + (point.Y.WebToStringR().Replace(",", ".")) + komma);

                                        komma = ", ";
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(wkt.ToString());
        }