Example #1
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Text&gt;
 /// format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process.</param>
 /// <param name="level"></param>
 /// <param name="indentFirst"></param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiLineStringText(MultiLineString multiLineString, int level, bool indentFirst,
                                          StringWriter writer)
 {
     if (multiLineString.IsEmpty())
     {
         writer.Write("EMPTY");
     }
     else
     {
         int  level2   = level;
         bool doIndent = indentFirst;
         writer.Write("(");
         for (int i = 0; i < multiLineString.GetNumGeometries(); i++)
         {
             if (i > 0)
             {
                 writer.Write(", ");
                 level2   = level + 1;
                 doIndent = true;
             }
             //AppendLineStringText((LineString) multiLineString.GetGeometryN(i), level2, doIndent, writer);
             AppendLineStringText((LineString)multiLineString.GetGeometryN(i), level2, doIndent, writer);
         }
         writer.Write(")");
     }
 }
Example #2
0
        public void test_GetBoundary()
        {
            MultiPolygon    mp1 = CreateMP1();
            MultiLineString mls = mp1.GetBoundary() as MultiLineString;

            for (int i = 0; i < mls.GetNumGeometries(); i++)
            {
                Assertion.AssertEquals("GetBoundary: ", true, mls[i].GetCoordinates().Equals(_mls1[i].GetCoordinates()));
            }
        }
Example #3
0
        public void test_GetBoundary()
        {
            Polygon         poly = Poly1();
            MultiLineString mls  = poly.GetBoundary() as MultiLineString;

            Assertion.AssertEquals("GetBoundary-1: ", 1, mls.GetNumGeometries());
            Assertion.AssertEquals("GetBoundary-2: ", 9, mls.GetNumPoints());
            Coordinates coords = mls.GetCoordinates();

            for (int i = 0; i < 9; i++)
            {
                Assertion.AssertEquals("GetBoundary-3: ", true, coords[i].Equals(_exterior1.GetCoordinateN(i)));
            }
        }
        public void test_NumGeometries()
        {
            //create a geomerty collection
            MultiLineString multiLS = CreateMLS();

            Assertion.AssertEquals("NumGeometries-1: ", 10, multiLS.GetNumGeometries());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            multiLS = gf.CreateMultiLineString(null);

            Assertion.AssertEquals("NumGeometries-2: ", 0, multiLS.GetNumGeometries());

            //now try it with a different geometry collection
            multiLS = closedMLS();

            Assertion.AssertEquals("NumGeometries-3: ", 2, multiLS.GetNumGeometries());

            //now try it with a mixed geometry collection
            multiLS = nonSimpleMLS();

            Assertion.AssertEquals("NumGeometries-4: ", 1, multiLS.GetNumGeometries());
        }
Example #5
0
        /// <summary>
        /// Writes a multilinestring.
        /// </summary>
        /// <param name="mls">The multilinestring to be written.</param>
        private void WriteMultiLineString(MultiLineString mls, byte format)
        {
            //Get the number of linestrings in this multilinestring.
            int numLineStrings = mls.GetNumGeometries();

            //Write the number of linestrings.
            _bWriter.Write(numLineStrings);

            //Loop on the number of linestrings.
            for (int i = 0; i < numLineStrings; i++)
            {
                //Write each linestring.
                WriteLineString((LineString)mls[i], format);
            }
        }
Example #6
0
        }         // public int Locate( Coordinate p, Geometry geom )

        private void ComputeLocation(Coordinate p, Geometry geom)
        {
            if (geom is LineString)
            {
                UpdateLocationInfo(Locate(p, (LineString)geom));
            }
            if (geom is LinearRing)
            {
                UpdateLocationInfo(Locate(p, (LinearRing)geom));
            }
            else if (geom is Polygon)
            {
                UpdateLocationInfo(Locate(p, (Polygon)geom));
            }
            else if (geom is MultiLineString)
            {
                MultiLineString ml = (MultiLineString)geom;
                for (int i = 0; i < ml.GetNumGeometries(); i++)
                {
                    LineString l = (LineString)ml.GetGeometryN(i);
                    UpdateLocationInfo(Locate(p, l));
                }                 // for ( int i = 0; i < ml.NumGeometries; i++ )
            }
            else if (geom is MultiPolygon)
            {
                MultiPolygon mpoly = (MultiPolygon)geom;
                for (int i = 0; i < mpoly.GetNumGeometries(); i++)
                {
                    Polygon poly = (Polygon)mpoly.GetGeometryN(i);
                    UpdateLocationInfo(Locate(p, poly));
                }                 // for (int i = 0; i < mpoly.NumGeometries; i++)
            }
            else if (geom is GeometryCollection)
            {
                GeometryCollection gc = geom as GeometryCollection;
                foreach (Geometry g2 in gc)
                {
                    if (g2 != geom)
                    {
                        ComputeLocation(p, g2);
                    }
                } // foreach( Geometry g2 in gc )
            }     // else if ( geom is GeometryCollection )
        }         // private void ComputeLocation(Coordinate p, Geometry geom)
Example #7
0
        /// <summary>
        /// Writes to the given stream the equilivent shape file record given a Geometry object.
        /// </summary>
        /// <param name="geometry">The geometry object to write.</param>
        /// <param name="file">The stream to write to.</param>
        /// <param name="geometryFactory">The geometry factory to use.</param>
        public override void Write(Geometry geometry, System.IO.BinaryWriter file, GeometryFactory geometryFactory)
        {
            MultiLineString multi = (MultiLineString)geometry;

            file.Write(int.Parse(Enum.Format(typeof(ShapeType), this.ShapeType, "d")));

            Envelope box = multi.GetEnvelopeInternal();

            file.Write(box.MinX);
            file.Write(box.MinY);
            file.Write(box.MaxX);
            file.Write(box.MaxY);

            int numParts  = multi.GetNumGeometries();
            int numPoints = multi.GetNumPoints();

            file.Write(numParts);
            file.Write(numPoints);

            //LineString[] lines = new LineString[numParts];

            // write the offsets
            int offset = 0;

            for (int i = 0; i < numParts; i++)
            {
                Geometry g = multi.GetGeometryN(i);
                file.Write(offset);
                offset = offset + g.GetNumPoints();
            }

            Coordinate external;

            for (int part = 0; part < numParts; part++)
            {
                Coordinates points = multi.GetGeometryN(part).GetCoordinates();
                for (int i = 0; i < points.Count; i++)
                {
                    external = geometryFactory.PrecisionModel.ToExternal(points[i]);
                    file.Write(external.X);
                    file.Write(external.Y);
                }
            }
        }
Example #8
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Text&gt;
 /// format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process.</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiLineStringText(MultiLineString multiLineString, TextWriter writer)
 {
     if (multiLineString.IsEmpty())
     {
         writer.Write("EMPTY");
     }
     else
     {
         for (int i = 0; i < multiLineString.GetNumGeometries(); i++)
         {
             if (i > 0)
             {
                 writer.Write(", ");
             }
             //AppendLineStringText((LineString) multiLineString.GetGeometryN(i), level2, doIndent, writer);
             AppendLineStringText((LineString)multiLineString.GetGeometryN(i), writer);
         }
         //writer.Write(")");
     }
 }
        public void TestMultiLineString1()
        {
            string wkt = "MULTILINESTRING (( 10.05  10.28 , 20.95  20.89 ),( 20.95  20.89, 31.92 21.45)) ";

            GeometryFactory factory         = new GeometryFactory();
            IGeometry       geometry        = factory.CreateFromWKT(wkt);
            MultiLineString multilineString = (MultiLineString)geometry;

            Assertion.AssertEquals("Multilinestring 1", 2, multilineString.GetNumGeometries());
            LineString linestring1 = (LineString)multilineString.GetGeometryN(0);
            LineString linestring2 = (LineString)multilineString.GetGeometryN(1);

            Assertion.AssertEquals("MLS 1", 10.05, linestring1.GetCoordinates()[0].X);
            Assertion.AssertEquals("MLS 2", 10.28, linestring1.GetCoordinates()[0].Y);
            Assertion.AssertEquals("MLS 3", 20.95, linestring1.GetCoordinates()[1].X);
            Assertion.AssertEquals("MLS 4", 20.89, linestring1.GetCoordinates()[1].Y);
            Assertion.AssertEquals("MLS 1", 20.95, linestring2.GetCoordinates()[0].X);
            Assertion.AssertEquals("MLS 2", 20.89, linestring2.GetCoordinates()[0].Y);
            Assertion.AssertEquals("MLS 3", 31.92, linestring2.GetCoordinates()[1].X);
            Assertion.AssertEquals("MLS 4", 21.45, linestring2.GetCoordinates()[1].Y);
            string wkt2 = ((MultiLineString)multilineString).ToText();

            Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2));
        }