Пример #1
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="level"></param>
 /// <param name="writer">The output stream to Append to.</param>
 protected void AppendMultiPolygonText(MultiPolygon multiPolygon, int level, StringWriter writer)
 {
     if (multiPolygon.isEmpty())
     {
         writer.Write("EMPTY");
     }
     else
     {
         int  level2   = level;
         bool doIndent = false;
         writer.Write("(");
         for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
         {
             if (i > 0)
             {
                 writer.Write(", ");
                 level2   = level + 1;
                 doIndent = true;
             }
             //AppendPolygonText((Polygon) multiPolygon.GetGeometryN(i), level2, doIndent, writer);
             AppendPolygonText((Polygon)multiPolygon.getGeometryN(i), level2, doIndent, writer);
         }
         writer.Write(")");
     }
 }
Пример #2
0
        /// <summary>
        /// Returns the largest <b>Polygon</b> in terms of area contained in the <b>MultiPolygon</b>.
        /// </summary>
        /// <param name="multiPolygon">The <b>MultiPolygon</b>.</param>
        /// <returns>The largest <b>Polygon</b> in terms of area contained in the <b>MultiPolygon</b>.</returns>
        /// <exception cref="ArgumentException"><i>multiPolygon</i> does not contain any <b>Polygon</b> objects.</exception>
        public static Polygon GetLargestPolygon(MultiPolygon multiPolygon)
        {
            if (multiPolygon.getNumGeometries() == 0)
            {
                throw new ArgumentException("MultiPolygon contains no polygons.", "multiPolygon");
            }

            Polygon largest = (Polygon)multiPolygon.getGeometryN(0);

            for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
            {
                if (multiPolygon.getGeometryN(i).getArea() > largest.getArea())
                {
                    largest = (Polygon)multiPolygon.getGeometryN(i);
                }
            }
            return(largest);
        }
Пример #3
0
        private static Geometry Simplify(MultiPolygon multipolygon, double tolerance)
        {
            GeometryFactory gf = new GeometryFactory();

            Polygon[] generalizedPolygons = new Polygon[multipolygon.getNumGeometries()];
            for (int i = 0; i < generalizedPolygons.Length; i++)
            {
                Polygon polygon = (Polygon)multipolygon.getGeometryN(i);
                generalizedPolygons[i] = Simplify(polygon, tolerance);
            }
            MultiPolygon multiPolygon = gf.createMultiPolygon(generalizedPolygons);

            return(multiPolygon);
        }
Пример #4
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="writer">The output stream to Append to.</param>
 public void AppendMultiPolygonText(MultiPolygon multiPolygon, TextWriter writer)
 {
     if (multiPolygon.isEmpty())
     {
         writer.Write("EMPTY");
     }
     else
     {
         //writer.Write("M");
         for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
         {
             /*if (i > 0 && (i<multiPolygon.GetNumGeometries()-1) )
              * {
              *      writer.Write(", ");
              * }*/
             AppendPolygonText((Polygon)multiPolygon.getGeometryN(i), writer);
         }
         //writer.Write("Z");
     }
 }
Пример #5
0
        private void WriteMultiPolygon(MultiPolygon mp, WKBByteOrder byteOrder)
        {
            // Write byte order
            _writer.Write((byte)byteOrder);

            // Write type
            this.WriteType(mp, byteOrder);

            // Get the number of polygons in this multipolygon.
            int numpolygons = mp.getNumGeometries();

            // Write the number of polygons.
            this.Write((uint)numpolygons, byteOrder);

            for (int i = 0; i < numpolygons; i++)
            {
                // Write each polygon.
                this.WritePolygon((Polygon)mp.getGeometryN(i), byteOrder);
            }
        }
Пример #6
0
        private int GetNumParts(Geometry geometry)
        {
            int numParts = 0;

            if (geometry is MultiPolygon)
            {
                numParts = 0;
                MultiPolygon multiPolygon = (MultiPolygon)geometry;
                for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
                {
                    numParts = numParts + GetNumParts(multiPolygon.getGeometryN(i));
                }
            }
            else if (geometry is Polygon)
            {
                numParts = ((Polygon)geometry).getNumInteriorRing() + 1;
            }
            else
            {
                throw new InvalidOperationException("Should not get here.");
            }

            return(numParts);
        }
Пример #7
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="level"></param>
 /// <param name="writer">The output stream to Append to.</param>
 protected void AppendMultiPolygonText(MultiPolygon multiPolygon, int level, StringWriter writer)
 {
     if ( multiPolygon.isEmpty() )
     {
         writer.Write("EMPTY");
     }
     else
     {
         int level2 = level;
         bool doIndent = false;
         writer.Write("(");
         for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
         {
             if (i > 0)
             {
                 writer.Write(", ");
                 level2 = level + 1;
                 doIndent = true;
             }
             //AppendPolygonText((Polygon) multiPolygon.GetGeometryN(i), level2, doIndent, writer);
             AppendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer);
         }
         writer.Write(")");
     }
 }
Пример #8
0
        private void WriteMultiPolygon(MultiPolygon mp, WKBByteOrder byteOrder)
        {
            // Write byte order
            _writer.Write((byte)byteOrder);

            // Write type
            this.WriteType(mp, byteOrder);

            // Get the number of polygons in this multipolygon.
            int numpolygons = mp.getNumGeometries();

            // Write the number of polygons.
            this.Write((uint)numpolygons, byteOrder);

            for (int i = 0; i < numpolygons; i++)
            {
                // Write each polygon.
                this.WritePolygon((Polygon)mp.getGeometryN(i), byteOrder);
            }
        }
Пример #9
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="writer">The output stream to Append to.</param>
 public void AppendMultiPolygonText(MultiPolygon multiPolygon, TextWriter writer)
 {
     if (multiPolygon.isEmpty())
     {
         writer.Write("EMPTY");
     }
     else
     {
         //writer.Write("M");
         for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
         {
             /*if (i > 0 && (i<multiPolygon.GetNumGeometries()-1) )
             {
                 writer.Write(", ");
             }*/
             AppendPolygonText((Polygon) multiPolygon.getGeometryN(i), writer);
         }
         //writer.Write("Z");
     }
 }