A MultiLineString is a MultiCurve whose elements are LineStrings.
Inheritance: MultiCurve
Exemplo n.º 1
0
		public void MultiLinestring()
		{
			MultiLineString mls = new MultiLineString();
			Assert.IsTrue(mls.IsEmpty());
			mls.LineStrings.Add(new LineString());
			Assert.IsTrue(mls.IsEmpty());
			mls.LineStrings[0].Vertices.Add(new Point(45, 68));
			mls.LineStrings[0].Vertices.Add(new Point(82, 44));
			mls.LineStrings.Add(CreateLineString());
			foreach (LineString ls in mls)
				Assert.IsFalse(ls.IsEmpty());
			Assert.IsFalse(mls.IsEmpty());
			foreach (LineString ls in mls)
				Assert.IsFalse(ls.IsClosed);
			Assert.IsFalse(mls.IsClosed);
			//Close linestrings
			foreach (LineString ls in mls)
				ls.Vertices.Add(ls.StartPoint.Clone());
			foreach (LineString ls in mls)
				Assert.IsTrue(ls.IsClosed);
			Assert.IsTrue(mls.IsClosed);
			Assert.AreEqual(new BoundingBox(1,2,930,123), mls.GetBoundingBox());
		}
Exemplo n.º 2
0
 public static void DrawMultiLineString(Graphics g, MultiLineString lines, Pen pen, Map map, float offset)
 {
     for (int i = 0; i < lines.LineStrings.Count; i++)
         DrawLineString(g, lines.LineStrings[i], pen, map, offset);
 }
Exemplo n.º 3
0
            public void EndFigure()
            {
                GeometryType type = _CurrentType.Peek();

                switch (type)
                {
                case GeometryType.GeometryCollection:
                {
                    var g = new SmGeometries.GeometryCollection();
                    g.Collection = _Figures;
                    _Figures     = new SmGeometries.Geometry[] { g };
                }
                break;

                case GeometryType.LineString:
                    _Figures.Add(new SmGeometries.LineString(_CurrentPoints));
                    break;

                case GeometryType.MultiLineString:
                {
                    var g = new SmGeometries.MultiLineString();
                    g.LineStrings = _Figures.Cast <SmGeometries.LineString>().ToList <SmGeometries.LineString>();
                    _Figures      = new SmGeometries.Geometry[] { g };
                }
                break;

                case GeometryType.MultiPoint:
                {
                    var g = new SmGeometries.MultiPoint();
                    g.Points = _Figures.Cast <SmGeometries.Point>().ToList <SmGeometries.Point>();
                    _Figures = new SmGeometries.Geometry[] { g };
                }
                break;

                case GeometryType.MultiPolygon:
                {
                    var g = new SmGeometries.MultiPolygon();
                    g.Polygons = _Figures.Cast <SmGeometries.Polygon>().ToList <SmGeometries.Polygon>();
                    _Figures   = new SmGeometries.Geometry[] { g };
                }
                break;

                case GeometryType.Point:
                    if (_CurrentPoints.Count > 0)
                    {
                        _Figures.Add(_CurrentPoints[0]);
                    }
                    else
                    {
                        _Figures.Add(new SmGeometries.Point());
                    }
                    break;

                case GeometryType.Polygon:
                    _Figures.Add(new SmGeometries.LinearRing(_CurrentPoints));
                    break;

                default:
                    throw new NotSupportedException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  SR.UnsupportedGeometryTypeException,
                                  type
                                  )
                              );
                }

                _CurrentPoints.Clear();
            }
		/// <summary>
		/// Transforms a <see cref="SharpMap.Geometries.MultiLineString"/>.
		/// </summary>
		/// <param name="lines">MultiLineString to transform</param>
		/// <param name="transform">MathTransform</param>
		/// <returns>Transformed MultiLineString</returns>
		public static MultiLineString TransformMultiLineString(MultiLineString lines, IMathTransform transform)
		{
            MultiLineString lOut = new MultiLineString(lines.LineStrings.Count);

            foreach (LineString l in lines)
                lOut.LineStrings.Add(TransformLineString(l, transform));

			return lOut;
		}
Exemplo n.º 5
0
        /// <summary>
        /// Reads and parses the geometry with ID 'oid' from the ShapeFile
        /// </summary>
        /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks>
        /// <param name="oid">Object ID</param>
        /// <returns>geometry</returns>
        private Geometry ReadGeometry(uint oid)
        {
            brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length
            ShapeType type = (ShapeType) brShapeFile.ReadInt32(); //Shape type
            if (type == ShapeType.Null)
                return null;
            if (_ShapeType == ShapeType.Point || _ShapeType == ShapeType.PointM || _ShapeType == ShapeType.PointZ)
            {
                Point tempFeature = new Point();
                return new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble());
            }
            else if (_ShapeType == ShapeType.Multipoint || _ShapeType == ShapeType.MultiPointM ||
                     _ShapeType == ShapeType.MultiPointZ)
            {
                brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box
                MultiPoint feature = new MultiPoint();
                int nPoints = brShapeFile.ReadInt32(); // get the number of points
                if (nPoints == 0)
                    return null;
                for (int i = 0; i < nPoints; i++)
                    feature.Points.Add(new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()));

                return feature;
            }
            else if (_ShapeType == ShapeType.PolyLine || _ShapeType == ShapeType.Polygon ||
                     _ShapeType == ShapeType.PolyLineM || _ShapeType == ShapeType.PolygonM ||
                     _ShapeType == ShapeType.PolyLineZ || _ShapeType == ShapeType.PolygonZ)
            {
                brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box

                int nParts = brShapeFile.ReadInt32(); // get number of parts (segments)
                if (nParts == 0)
                    return null;
                int nPoints = brShapeFile.ReadInt32(); // get number of points

                int[] segments = new int[nParts + 1];
                //Read in the segment indexes
                for (int b = 0; b < nParts; b++)
                    segments[b] = brShapeFile.ReadInt32();
                //add end point
                segments[nParts] = nPoints;

                if ((int) _ShapeType%10 == 3)
                {
                    MultiLineString mline = new MultiLineString();
                    for (int LineID = 0; LineID < nParts; LineID++)
                    {
                        LineString line = new LineString();
                        for (int i = segments[LineID]; i < segments[LineID + 1]; i++)
                            line.Vertices.Add(new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()));
                        mline.LineStrings.Add(line);
                    }
                    if (mline.LineStrings.Count == 1)
                        return mline[0];
                    return mline;
                }
                else //(_ShapeType == ShapeType.Polygon etc...)
                {
                    //First read all the rings
                    List<LinearRing> rings = new List<LinearRing>();
                    for (int RingID = 0; RingID < nParts; RingID++)
                    {
                        LinearRing ring = new LinearRing();
                        for (int i = segments[RingID]; i < segments[RingID + 1]; i++)
                            ring.Vertices.Add(new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()));
                        rings.Add(ring);
                    }
                    bool[] IsCounterClockWise = new bool[rings.Count];
                    int PolygonCount = 0;
                    for (int i = 0; i < rings.Count; i++)
                    {
                        IsCounterClockWise[i] = rings[i].IsCCW();
                        if (!IsCounterClockWise[i])
                            PolygonCount++;
                    }
                    if (PolygonCount == 1) //We only have one polygon
                    {
                        Polygon poly = new Polygon();
                        poly.ExteriorRing = rings[0];
                        if (rings.Count > 1)
                            for (int i = 1; i < rings.Count; i++)
                                poly.InteriorRings.Add(rings[i]);
                        return poly;
                    }
                    else
                    {
                        MultiPolygon mpoly = new MultiPolygon();
                        Polygon poly = new Polygon();
                        poly.ExteriorRing = rings[0];
                        for (int i = 1; i < rings.Count; i++)
                        {
                            if (!IsCounterClockWise[i])
                            {
                                mpoly.Polygons.Add(poly);
                                poly = new Polygon(rings[i]);
                            }
                            else
                                poly.InteriorRings.Add(rings[i]);
                        }
                        mpoly.Polygons.Add(poly);
                        return mpoly;
                    }
                }
            }
            else
                throw (new ApplicationException("Shapefile type " + _ShapeType.ToString() + " not supported"));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Transforms a <see cref="SharpMap.Geometries.MultiLineString"/>.
 /// </summary>
 /// <param name="lines">MultiLineString to transform</param>
 /// <param name="transform">MathTransform</param>
 /// <returns>Transformed MultiLineString</returns>
 public static MultiLineString TransformMultiLineString(MultiLineString lines, IMathTransform transform)
 {
     MultiLineString lOut = new MultiLineString();
     //lOut.LineStrings = new Collection<LineString>(lines.LineStrings.Count); //Pre-inialize array size for better performance
     lOut.LineStrings = new Collection<LineString>(); //Pre-inialize array size for better performance
     for (int i = 0; i < lines.LineStrings.Count; i++)
         lOut.LineStrings.Add(TransformLineString(lines[i], transform));
     return lOut;
 }
Exemplo n.º 7
0
        /// <summary>
        /// This method produces instances of type <see cref="SharpMap.Geometries.MultiLineString"/>.
        /// </summary>
        /// <returns>The created geometries</returns>
        internal override Collection<Geometry> createGeometries()
        {
            MultiLineString multiLineString = null;

            IPathNode multiLineStringNode = new PathNode(_GMLNS, "MultiLineString", (NameTable) _XmlReader.NameTable);
            IPathNode multiCurveNode = new PathNode(_GMLNS, "MultiCurve", (NameTable) _XmlReader.NameTable);
            IPathNode multiLineStringNodeAlt = new AlternativePathNodesCollection(multiLineStringNode, multiCurveNode);
            IPathNode lineStringMemberNode = new PathNode(_GMLNS, "lineStringMember", (NameTable) _XmlReader.NameTable);
            IPathNode curveMemberNode = new PathNode(_GMLNS, "curveMember", (NameTable) _XmlReader.NameTable);
            IPathNode lineStringMemberNodeAlt = new AlternativePathNodesCollection(lineStringMemberNode, curveMemberNode);
            string[] labelValue = new string[1];
            bool geomFound = false;

            try
            {
                // Reading the entire feature's node makes it possible to collect label values that may appear before or after the geometry property
                while ((_FeatureReader = GetSubReaderOf(_XmlReader, null, _FeatureNode)) != null)
                {
                    while (
                        (_GeomReader =
                         GetSubReaderOf(_FeatureReader, labelValue, multiLineStringNodeAlt, lineStringMemberNodeAlt)) !=
                        null)
                    {
                        multiLineString = new MultiLineString();
                        GeometryFactory geomFactory = new LineStringFactory(_GeomReader, _FeatureTypeInfo);
                        Collection<Geometry> lineStrings = geomFactory.createGeometries();

                        foreach (LineString lineString in lineStrings)
                            multiLineString.LineStrings.Add(lineString);

                        _Geoms.Add(multiLineString);
                        geomFound = true;
                    }
                    if (geomFound) AddLabel(labelValue[0], _Geoms[_Geoms.Count - 1]);
                    geomFound = false;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("An exception occured while parsing a multi-lineString geometry: " + ex.Message);
                throw ex;
            }

            return _Geoms;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Tagged
 /// 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>
 private static void AppendMultiLineStringTaggedText(MultiLineString multiLineString, StringWriter writer)
 {
     writer.Write("MULTILINESTRING ");
     AppendMultiLineStringText(multiLineString, writer);
 }
        /// <summary>
        /// Transforms a <see cref="SharpMap.Geometries.MultiLineString"/>.
        /// </summary>
        /// <param name="lines">MultiLineString to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <returns>Transformed MultiLineString</returns>
        public static MultiLineString TransformMultiLineString(MultiLineString lines, ProjectionInfo from, ProjectionInfo to)
        {
            var lOut = new MultiLineString {LineStrings = new Collection<LineString>()};

            for (var i = 0; i < lines.LineStrings.Count; i++)
                lOut.LineStrings.Add(TransformLineString(lines[i], from, to));
            return lOut;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Return a copy of this geometry
 /// </summary>
 /// <returns>Copy of Geometry</returns>
 public new MultiLineString Clone()
 {
     MultiLineString geoms = new MultiLineString();
     for (int i = 0; i < _LineStrings.Count; i++)
         geoms.LineStrings.Add(_LineStrings[i].Clone());
     return geoms;
 }
Exemplo n.º 11
0
 /// <summary>  
 /// Converts a MultiLineString to &lt;MultiLineString Tagged  
 /// 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>  
 private static void AppendMultiLineStringTaggedText(MultiLineString multiLineString, StringWriter writer)
 {
   //{  
   //   "type": "MultiLineString",  
   //   "coordinates": [  
   //       [ [100.0, 0.0], [101.0, 1.0] ],  
   //       [ [102.0, 2.0], [103.0, 3.0] ]  
   //   ]  
   //}  
   writer.WriteLine("{");
   writer.WriteLine("\"type\": \"MultiLineString\",");
   writer.WriteLine("\"coordinates\": ");
   AppendMultiLineStringText(multiLineString, writer);
   writer.WriteLine("}");
 }
Exemplo n.º 12
0
		/// <summary>
		/// Writes a multilinestring.
		/// </summary>
		/// <param name="mls">The multilinestring to be written.</param>
		/// <param name="bWriter">Stream to write to.</param>
		/// <param name="byteorder">Byte order</param>
		private static void WriteMultiLineString(MultiLineString mls, BinaryWriter bWriter, WkbByteOrder byteorder)
		{
			//Write the number of linestrings.
			WriteUInt32((uint)mls.LineStrings.Count, bWriter, byteorder);
			
			//Loop on the number of linestrings.
			foreach (LineString ls in mls.LineStrings)
			{
				//Write LineString Header
				bWriter.Write((byte)byteorder);
				WriteUInt32((uint)WKBGeometryType.wkbLineString, bWriter, byteorder);
				//Write each linestring.
				WriteLineString(ls, bWriter, byteorder);
			}
		}
Exemplo n.º 13
0
            public void EndFigure()
            {
                GeometryType type=_CurrentType.Peek();
                switch (type)
                {
                case GeometryType.GeometryCollection:
                    {
                        var g=new SmGeometries.GeometryCollection();
                        g.Collection=_Figures;
                        _Figures=new SmGeometries.Geometry[] { g };
                    }
                    break;
                case GeometryType.LineString:
                    _Figures.Add(new SmGeometries.LineString(_CurrentPoints));
                    break;
                case GeometryType.MultiLineString:
                    {
                        var g=new SmGeometries.MultiLineString();
                        g.LineStrings=_Figures.Cast<SmGeometries.LineString>().ToList<SmGeometries.LineString>();
                        _Figures=new SmGeometries.Geometry[] { g };
                    }
                    break;
                case GeometryType.MultiPoint:
                    {
                        var g=new SmGeometries.MultiPoint();
                        g.Points=_Figures.Cast<SmGeometries.Point>().ToList<SmGeometries.Point>();
                        _Figures=new SmGeometries.Geometry[] { g };
                    }
                    break;
                case GeometryType.MultiPolygon:
                    {
                        var g=new SmGeometries.MultiPolygon();
                        g.Polygons=_Figures.Cast<SmGeometries.Polygon>().ToList<SmGeometries.Polygon>();
                        _Figures=new SmGeometries.Geometry[] { g };
                    }
                    break;
                case GeometryType.Point:
                    if (_CurrentPoints.Count>0)
                        _Figures.Add(_CurrentPoints[0]);
                    else
                        _Figures.Add(new SmGeometries.Point());
                    break;
                case GeometryType.Polygon:
                    _Figures.Add(new SmGeometries.LinearRing(_CurrentPoints));
                    break;
                default:
                    throw new NotSupportedException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            SR.UnsupportedGeometryTypeException,
                            type
                        )
                    );
                }

                _CurrentPoints.Clear();
            }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a <see cref="MultiLineString"/> using the next token in the stream. 
        /// </summary>
        /// <param name="tokenizer">tokenizer over a stream of text in Well-known Text format. The next tokens must form a MultiLineString Text</param>
        /// <returns>a <see cref="MultiLineString"/> specified by the next token in the stream</returns>
        private static MultiLineString ReadMultiLineStringText(WktStreamTokenizer tokenizer)
        {
            MultiLineString lines = new MultiLineString();
            string nextToken = GetNextEmptyOrOpener(tokenizer);
            if (nextToken == "EMPTY")
                return lines;

            lines.LineStrings.Add(ReadLineStringText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                lines.LineStrings.Add(ReadLineStringText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return lines;
        }
Exemplo n.º 15
0
        private static Geometry FromShapeFilePolyLine(EsriShapeBuffer shapeBuffer, out BoundingBox box)
        {
            box = null;
            if (shapeBuffer == null)
                return null;

            var hasZ = EsriShapeBuffer.HasZs(shapeBuffer.shapeType);
            var hasM = EsriShapeBuffer.HasMs(shapeBuffer.shapeType);
            using (var reader = new BinaryReader(new MemoryStream(shapeBuffer.shapeBuffer)))
            {
                var type = reader.ReadInt32();
                if (!(type == 3 || type == 13 || type == 23))
                    throw new InvalidOperationException();

                box = new BoundingBox(reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble());

                var numParts = reader.ReadInt32();
                var numPoints = reader.ReadInt32();
                var allVertices = new List<Point>(numPoints);

                var parts = new int[numParts+1];
                for (var i = 0; i < numParts; i++)
                    parts[i] = reader.ReadInt32();
                parts[numParts] = numPoints;

                var res = new MultiLineString();
                var lines = res.LineStrings;

                for (var i = 0; i < numParts; i++)
                {
                    var count = parts[i + 1] - parts[i];
                    var vertices = new List<Point>(count);
                    for (var j = 0; j < count; j++)
                    {
                        var vertex = hasZ
                                         ? new Point3D(reader.ReadDouble(), reader.ReadDouble(), double.NaN)
                                         : new Point(reader.ReadDouble(), reader.ReadDouble());
                        vertices.Add(vertex);
                        allVertices.Add(vertex);
                    }

                    lines.Add(new LineString(vertices));
                }

                if (hasZ)
                {
                    var minZ = reader.ReadDouble();
                    var maxZ = reader.ReadDouble();
                    for (var i = 0; i < numPoints; i++)
                        ((Point3D) allVertices[i]).Z = reader.ReadDouble();
                }

                if (res.NumGeometries == 1)
                    return lines[0];

                return res;

            }
        }
Exemplo n.º 16
0
        private static MultiLineString CreateWKBMultiLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // Get the number of linestrings in this multilinestring.
            int numLineStrings = (int) ReadUInt32(reader, byteOrder);

            // Create a new array for the linestrings .
            MultiLineString mline = new MultiLineString();

            // Loop on the number of linestrings.
            for (int i = 0; i < numLineStrings; i++)
            {
                // Read linestring header
                reader.ReadByte();
                ReadUInt32(reader, byteOrder);

                // Create the next linestring and add it to the array.
                mline.LineStrings.Add(CreateWKBLineString(reader, byteOrder));
            }

            // Create and return the MultiLineString.
            return mline;
        }
Exemplo n.º 17
0
        private static Geometry ToSharpMapMultiLineString(EsriShapeBuffer shapeBuffer)
        {
            if (shapeBuffer == null)
                return null;

            var multiPartShapeBuffer = shapeBuffer as EsriMultiPartShapeBuffer;
            if (multiPartShapeBuffer == null)
            {
                BoundingBox box;
                return FromShapeFilePolyLine(shapeBuffer, out box);
            }

            var hasZ = EsriShapeBuffer.HasZs(shapeBuffer.shapeType);
            var res = new MultiLineString();
            var lines = res.LineStrings;

            var offset = 0;
            for (var i = 0; i < multiPartShapeBuffer.NumParts; i++)
            {
                var vertices = new List<Point>(multiPartShapeBuffer.Parts[i]);
                for (var j = 0; j < multiPartShapeBuffer.Parts[i]; j++ )
                {
                    var index = offset + j;
                    var point = multiPartShapeBuffer.Points[index];
                    vertices.Add(hasZ
                            ? new Point3D(point.x, point.y, multiPartShapeBuffer.Zs[index])
                            : new Point(point.x, point.y));
                }
                lines.Add(new LineString(vertices));
                offset += multiPartShapeBuffer.Parts[i];
            }
            
            if (lines.Count == 1)
                return lines[0];
            return res;
        }
Exemplo n.º 18
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>
 private static void AppendMultiLineStringText(MultiLineString multiLineString, StringWriter writer)
 {
     if (multiLineString == null || multiLineString.IsEmpty())
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (int i = 0; i < multiLineString.LineStrings.Count; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendLineStringText(multiLineString[i], writer);
         }
         writer.Write(")");
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lineStrings"></param>
        /// <returns></returns>
        public MultiLineString ClipLineString(MultiLineString lineStrings)
        {
            var clippedLineStrings = new List<LineString>();


            foreach (LineString s in lineStrings)
                clippedLineStrings.AddRange(ClipLineString(s).LineStrings);


            return new MultiLineString { LineStrings = clippedLineStrings };
        }