private IntPtr WriteShpGeometryField(int iShape, Point point)
        {
            var xArray = new[] { point.Coordinate.X };
            var yArray = new[] { point.Coordinate.Y };

            return(ShapeLib.SHPCreateObject(ShapeType.Point, iShape, 0, null, null, xArray.Length, xArray, yArray, null, null));
        }
        private IntPtr WriteShpGeometryField(int iShape, MultiPoint multiPoint)
        {
            var nvertices  = 0;
            var apartStart = new List <int>();
            var vX         = new List <double>();
            var vY         = new List <double>();

            apartStart.Add(nvertices);

            for (var i = 0; i < multiPoint.Geometries.Length; i++)
            {
                var point = multiPoint.Geometries[i];

                var coordinate = point.Coordinate;

                vX.Add(coordinate.X);
                vY.Add(coordinate.Y);

                nvertices += 1;
                if (i + 1 != multiPoint.Geometries.Length)
                {
                    apartStart.Add(nvertices);
                }
            }

            return(ShapeLib.SHPCreateObject(ShapeType.MultiPoint, iShape, apartStart.Count, apartStart.ToArray(), null, nvertices, vX.ToArray(), vY.ToArray(), null, null));

            //var xArray = multiPoint.Geometries.Select(x => x.Coordinate.X).ToArray();
            //var yArray = multiPoint.Geometries.Select(x => x.Coordinate.Y).ToArray();

            //return ShapeLib.SHPCreateObject(ShapeType.Point, iShape, 0, null, null, xArray.Length, xArray, yArray, null, null);
        }
        private IntPtr WriteShpGeometryField(int iShape, Polygon polygon)
        {
            var exteriorRingVertices = polygon.OuterRing.Coordinates.ToList();

            exteriorRingVertices.Add(exteriorRingVertices.First());

            if (polygon.InnerRings.Count > 0)
            {
                var nvertices  = 0;
                var apartStart = new List <int>();
                var apartType  = new List <ShapeLib.PartType>();
                var vX         = new List <double>();
                var vY         = new List <double>();

                apartStart.Add(nvertices);
                apartType.Add(ShapeLib.PartType.Ring);
                nvertices += exteriorRingVertices.Count;
                for (var v = 0; v < exteriorRingVertices.Count; v++)
                {
                    vX.Add(exteriorRingVertices[v].X);
                    vY.Add(exteriorRingVertices[v].Y);
                }
                apartStart.Add(nvertices);

                for (var j = 0; j < polygon.InnerRings.Count; j++)
                {
                    var interiorRingVertices = polygon.InnerRings[j].Coordinates.ToList();
                    interiorRingVertices.Add(interiorRingVertices.First());
                    for (var v = 0; v < interiorRingVertices.Count; v++)
                    {
                        vX.Add(interiorRingVertices[v].X);
                        vY.Add(interiorRingVertices[v].Y);
                    }
                    nvertices += interiorRingVertices.Count;
                    if (j + 1 != polygon.InnerRings.Count)
                    {
                        apartStart.Add(nvertices);
                    }
                    apartType.Add(ShapeLib.PartType.Ring);
                }

                return(ShapeLib.SHPCreateObject(ShapeType.Polygon, iShape, apartStart.Count, apartStart.ToArray(), apartType.ToArray(), nvertices, vX.ToArray(), vY.ToArray(), null, null));
            }
            else
            {
                var vX = new List <double>();
                var vY = new List <double>();
                for (var v = 0; v < exteriorRingVertices.Count; v++)
                {
                    vX.Add(exteriorRingVertices[v].X);
                    vY.Add(exteriorRingVertices[v].Y);
                }
                return(ShapeLib.SHPCreateSimpleObject(ShapeType.Polygon, exteriorRingVertices.Count, vX.ToArray(), vY.ToArray(), null));
            }
        }
        private IntPtr WriteShpGeometryField(int iShape, MultiLineString multiLineString)
        {
            if (multiLineString.Geometries.Length == 1)
            {
                return(WriteShpGeometryField(iShape, multiLineString.Geometries[0]));
            }

            var nvertices  = 0;
            var apartStart = new List <int>();
            var vX         = new List <double>();
            var vY         = new List <double>();

            apartStart.Add(nvertices);

            for (var i = 0; i < multiLineString.Geometries.Length; i++)
            {
                var lineString = multiLineString.Geometries[i];

                var isClosed = lineString.CoordinateList.Coordinates.First().Equals(lineString.CoordinateList.Coordinates.Last());

                var coordinates = lineString.CoordinateList.Coordinates.ToList();
                if (isClosed)
                {
                    coordinates.Add(coordinates.First());
                }
                else
                {
                    coordinates.Add(coordinates.Last());
                }

                foreach (var coordinate in coordinates)
                {
                    vX.Add(coordinate.X);
                    vY.Add(coordinate.Y);
                }

                nvertices += coordinates.Count;
                if (i + 1 != multiLineString.Geometries.Length)
                {
                    apartStart.Add(nvertices);
                }
            }

            return(ShapeLib.SHPCreateObject(ShapeType.PolyLine, iShape, apartStart.Count, apartStart.ToArray(), null, nvertices, vX.ToArray(), vY.ToArray(), null, null));
        }
        private IntPtr WriteShpGeometryField(int iShape, LineString lineString)
        {
            var isClosed = lineString.CoordinateList.Coordinates.First().Equals(lineString.CoordinateList.Coordinates.Last());

            var coordinates = lineString.CoordinateList.Coordinates.ToList();

            if (isClosed)
            {
                coordinates.Add(coordinates.First());
            }
            else
            {
                coordinates.Add(coordinates.Last());
            }

            var xArray = coordinates.Select(x => x.X).ToArray();
            var yArray = coordinates.Select(x => x.Y).ToArray();

            return(ShapeLib.SHPCreateObject(ShapeType.PolyLine, iShape, 0, null, null, xArray.Length, xArray, yArray, null, null));
        }
        private IntPtr WriteShpGeometryField(int iShape, MultiPolygon multiPolygon)
        {
            if (multiPolygon.Geometries.Length == 1)
            {
                return(WriteShpGeometryField(iShape, multiPolygon.Geometries[0]));
            }

            var nvertices  = 0;
            var apartStart = new List <int>();
            var apartType  = new List <ShapeLib.PartType>();
            var vX         = new List <double>();
            var vY         = new List <double>();

            apartStart.Add(nvertices);

            for (var i = 0; i < multiPolygon.Geometries.Length; i++)
            {
                var polygon = multiPolygon.Geometries[i];

                var vertices = polygon.OuterRing.Coordinates;

                vX.AddRange(vertices.Select(x => x.X));
                vY.AddRange(vertices.Select(x => x.Y));

                vX.Add(vertices.First().X);
                vY.Add(vertices.First().Y);

                nvertices += vertices.Count;
                if (i + 1 != multiPolygon.Geometries.Length)
                {
                    apartStart.Add(nvertices);
                }
                apartType.Add(ShapeLib.PartType.Ring);
            }

            return(ShapeLib.SHPCreateObject(ShapeType.Polygon, iShape, apartStart.Count, apartStart.ToArray(), apartType.ToArray(), nvertices, vX.ToArray(), vY.ToArray(), null, null));
        }