A MultiPoint is a 0 dimensional geometric collection. The elements of a MultiPoint are restricted to Points. The points are not connected or ordered.
Inheritance: GeometryCollection
Beispiel #1
0
 public static void DrawMultiPoint(IPointSymbolizer symbolizer, Graphics g, MultiPoint points, Map map)
 {
     symbolizer.Render(map, points, g);
 }
		/// <summary>
		/// Transforms a <see cref="SharpMap.Geometries.MultiPoint"/>.
		/// </summary>
		/// <param name="points">MultiPoint to transform</param>
		/// <param name="transform">MathTransform</param>
		/// <returns>Transformed MultiPoint</returns>
		public static MultiPoint TransformMultiPoint(MultiPoint points, IMathTransform transform)
		{
			MultiPoint pOut = new MultiPoint(points.Points.Count);

            foreach (Point p in points.Points)
                pOut.Points.Add(transform.Transform(p));

			return pOut;
		}
Beispiel #3
0
 public static void DrawMultiPoint(Graphics g, MultiPoint points, Image symbol, float symbolscale, PointF offset,
                                   float rotation, Map map)
 {
     for (int i = 0; i < points.Points.Count; i++)
         DrawPoint(g, points.Points[i], symbol, symbolscale, offset, rotation, map);
 }
Beispiel #4
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"));
        }
Beispiel #5
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();
            }
Beispiel #6
0
 /// <summary>
 /// Return a copy of this geometry
 /// </summary>
 /// <returns>Copy of Geometry</returns>
 public new MultiPoint Clone()
 {
     MultiPoint geoms = new MultiPoint();
     for (int i = 0; i < _Points.Count; i++)
         geoms.Points.Add(_Points[i].Clone());
     return geoms;
 }
Beispiel #7
0
 /// <summary>
 /// Converts a MultiPoint to &lt;MultiPoint Tagged Text&gt;
 /// format, then Appends it to the writer.
 /// </summary>
 /// <param name="multipoint">The MultiPoint to process.</param>
 /// <param name="writer">The output writer to Append to.</param>
 private static void AppendMultiPointTaggedText(MultiPoint multipoint, StringWriter writer)
 {
     writer.Write("MULTIPOINT ");
     AppendMultiPointText(multipoint, writer);
 }
Beispiel #8
0
        /// <summary>
        /// This method produces instances of type <see cref="SharpMap.Geometries.MultiPoint"/>.
        /// </summary>
        /// <returns>The created geometries</returns>
        internal override Collection<Geometry> createGeometries()
        {
            MultiPoint multiPoint = null;

            IPathNode multiPointNode = new PathNode(_GMLNS, "MultiPoint", (NameTable) _XmlReader.NameTable);
            IPathNode pointMemberNode = new PathNode(_GMLNS, "pointMember", (NameTable) _XmlReader.NameTable);
            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, multiPointNode, pointMemberNode)) !=
                        null)
                    {
                        multiPoint = new MultiPoint();
                        GeometryFactory geomFactory = new PointFactory(_GeomReader, _FeatureTypeInfo);
                        Collection<Geometry> points = geomFactory.createGeometries();

                        foreach (Point point in points)
                            multiPoint.Points.Add(point);

                        _Geoms.Add(multiPoint);
                        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-point geometry: " + ex.Message);
                throw ex;
            }

            return _Geoms;
        }
        private static Geometry FromShapeFileMultiPoint(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 == 8 || type == 18 || type == 28))
                    throw new InvalidOperationException();

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

                var numPoints = reader.ReadInt32();

                var res = new MultiPoint();
                var points = res.Points;

                for (var i = 0; i < numPoints; i++)
                {
                    var vertex = hasZ
                                        ? new Point3D(reader.ReadDouble(), reader.ReadDouble(), double.NaN)
                                        : new Point(reader.ReadDouble(), reader.ReadDouble());
                    points.Add(vertex);
                }

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

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

                return res;

            }
        }
Beispiel #10
0
 /// <summary>  
 /// Converts a MultiPoint to &lt;MultiPoint Tagged Text&gt;  
 /// format, then Appends it to the writer.  
 /// </summary>  
 /// <param name="multipoint">The MultiPoint to process.</param>  
 /// <param name="writer">The output writer to Append to.</param>  
 private static void AppendMultiPointTaggedText(MultiPoint multipoint, StringWriter writer)
 {
   //{  
   //   "type": "MultiPoint",  
   //   "coordinates": [  
   //       [100.0, 0.0], [101.0, 1.0]  
   //   ]  
   //}  
   writer.WriteLine("{");
   writer.WriteLine("\"type\": \"MultiPoint\",");
   writer.WriteLine("\"coordinates\": ");
   AppendMultiPointText(multipoint, writer);
   writer.WriteLine("}");
 }
        /// <summary>
        /// Transforms a <see cref="SharpMap.Geometries.MultiPoint"/>.
        /// </summary>
        /// <param name="points">MultiPoint to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <returns>Transformed MultiPoint</returns>
        public static MultiPoint TransformMultiPoint(MultiPoint points, ProjectionInfo from, ProjectionInfo to)
        {
            var pts = new List<double[]>();
            for (var i = 0; i < points.NumGeometries; i++)
                pts.Add(new[] {points[i].X, points[i].Y});

            return new MultiPoint(TransformList(pts, from, to));
        }
Beispiel #12
0
 /// <summary>
 /// Method to render the <see cref="MultiPoint"/> to the <see cref="Graphics"/> object.
 /// </summary>
 /// <param name="map">The map object</param>
 /// <param name="points">Locations where to render the Symbol</param>
 /// <param name="g">The graphics object to use.</param>
 public void Render(Map map, MultiPoint points, Graphics g)
 {
     if (points == null)
         return;
     
     foreach (Point point in points)
         Render(map, point, g);
 }
Beispiel #13
0
		/// <summary>
		/// Writes a multipoint.
		/// </summary>
		/// <param name="mp">The multipoint to be written.</param>
		/// <param name="bWriter">Stream to write to.</param>
		/// <param name="byteorder">Byte order</param>
		private static void WriteMultiPoint(MultiPoint mp, BinaryWriter bWriter, WkbByteOrder byteorder)
		{
			//Write the number of points.
			WriteUInt32((uint)mp.Points.Count, bWriter, byteorder);
			
			//Loop on the number of points.
			foreach (Point p in mp.Points)
			{
				//Write Points Header
				bWriter.Write((byte)byteorder);
				WriteUInt32((uint)WKBGeometryType.wkbPoint, bWriter, byteorder);
				//Write each point.
				WritePoint((Point)p, bWriter, byteorder);
			}
		}
            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();
            }
Beispiel #15
0
 public static void DrawMultiPoint(Graphics g, MultiPoint points, Brush brush, float size, PointF offset, Map map)
 {
     for (int i = 0; i < points.Points.Count; i++)
         DrawPoint(g, points.Points[i], brush, size, offset, map);
 }
        private static Geometry ToSharpMapMultiPoint(EsriShapeBuffer shapeBuffer)
        {
            var multiPointShapeBuffer = shapeBuffer as EsriMultiPointShapeBuffer;
            if (multiPointShapeBuffer == null)
            {
                BoundingBox box;
                return FromShapeFileMultiPoint(shapeBuffer, out box);
            }

            var res = new MultiPoint();
            var hasZ = EsriShapeBuffer.HasZs(multiPointShapeBuffer.shapeType);
            var points = res.Points;
            var offset = 0;
            foreach (var point in multiPointShapeBuffer.Points)
                points.Add(hasZ 
                    ? new Point3D(point.x, point.y, multiPointShapeBuffer.Zs[offset++]) 
                    : new Point(point.x, point.y));

            return res;
        }
 /// <summary>
 /// Creates a Point 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 &lt;Point Text&gt;.</param>
 /// <returns>Returns a Point specified by the next token in
 /// the stream.</returns>
 /// <remarks>
 /// ParseException is thrown if an unexpected token is encountered.
 /// </remarks>
 private static MultiPoint ReadMultiPointText(WktStreamTokenizer tokenizer)
 {
     SharpMap.Geometries.MultiPoint mp = new MultiPoint();
     string nextToken = GetNextEmptyOrOpener(tokenizer);
     if (nextToken == "EMPTY")
         return mp;
     mp.Points.Add(new SharpMap.Geometries.Point(GetNextNumber(tokenizer),GetNextNumber(tokenizer)));
     nextToken = GetNextCloserOrComma(tokenizer);
     while (nextToken == ",")
     {
         mp.Points.Add(new SharpMap.Geometries.Point(GetNextNumber(tokenizer), GetNextNumber(tokenizer)));
         nextToken = GetNextCloserOrComma(tokenizer);
     }
     return mp;
 }
Beispiel #18
0
 /// <summary>
 /// Transforms a <see cref="SharpMap.Geometries.MultiPoint"/>.
 /// </summary>
 /// <param name="points">MultiPoint to transform</param>
 /// <param name="transform">MathTransform</param>
 /// <returns>Transformed MultiPoint</returns>
 public static MultiPoint TransformMultiPoint(MultiPoint points, IMathTransform transform)
 {
     MultiPoint pOut = new MultiPoint();
     pOut.Points = transform.TransformList(points.Points);
     return pOut;
 }
Beispiel #19
0
        private static MultiPoint CreateWKBMultiPoint(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // Get the number of points in this multipoint.
            int numPoints = (int) ReadUInt32(reader, byteOrder);

            // Create a new array for the points.
            MultiPoint points = new MultiPoint();

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

                // TODO: Validate type

                // Create the next point and add it to the point array.
                points.Points.Add(CreateWKBPoint(reader, byteOrder));
            }
            return points;
        }
Beispiel #20
0
        /// <summary>
        /// Transforms a <see cref="SharpMap.Geometries.MultiPoint"/>.
        /// </summary>
        /// <param name="points">MultiPoint to transform</param>
        /// <param name="transform">MathTransform</param>
        /// <returns>Transformed MultiPoint</returns>
        public static MultiPoint TransformMultiPoint(MultiPoint points, IMathTransform transform)
        {
            List<double[]> pts = new List<double[]>();
            for (int i = 0; i < points.NumGeometries; i++)
                pts.Add(new double[2] {points[i].X, points[i].Y});

            return new MultiPoint(transform.TransformList(pts));
        }
Beispiel #21
0
 /// <summary>
 /// Converts a MultiPoint to &lt;MultiPoint Text&gt; format, then
 /// Appends it to the writer.
 /// </summary>
 /// <param name="multiPoint">The MultiPoint to process.</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendMultiPointText(MultiPoint multiPoint, StringWriter writer)
 {
     if (multiPoint == null || multiPoint.IsEmpty())
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (int i = 0; i < multiPoint.Points.Count; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendCoordinate(multiPoint[i], writer);
         }
         writer.Write(")");
     }
 }
        /// <summary>
        /// Creates a Point 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 &lt;Point Text&gt;.
        /// </param>
        /// <returns>
        /// Returns a Point specified by the next token in
        /// the stream.
        /// </returns>
        /// <exception cref="ParseException">
        /// Thrown if an unexpected token is encountered.
        /// </exception>
        private static MultiPoint readMultiPointText(WktStreamTokenizer tokenizer)
        {
            MultiPoint mp = new MultiPoint();
            string nextToken = getNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return mp;
            }

            mp.Points.Add(new Point(getNextNumber(tokenizer), getNextNumber(tokenizer)));
            nextToken = getNextCloserOrComma(tokenizer);

            while (nextToken == ",")
            {
                mp.Points.Add(new Point(getNextNumber(tokenizer), getNextNumber(tokenizer)));
                nextToken = getNextCloserOrComma(tokenizer);
            }

            return mp;
        }