internal SqlGeography(ShapeData g, int srid)
 {
     this.srid      = srid;
     this._geometry = g;
 }
 public SqlGeography()
 {
     _geometry = new ShapeData();
 }
Beispiel #3
0
        private ShapeData ShapeToGeometry(int shapeIndex)
        {
            if (shapeIndex == 0)
            {
                return(this);
            }
            ShapeData geoDatum  = new ShapeData();
            var       shape     = _shapes[shapeIndex];
            var       nextShape = shapeIndex + 1;

            for (; nextShape < _shapes.Length; nextShape++)
            {
                if (_shapes[nextShape].ParentOffset == shape.ParentOffset)
                {
                    break;
                }
            }

            List <Shape>  shapes   = new List <Shape>(nextShape - shapeIndex);
            List <Figure> figures  = new List <Figure>();
            List <Point>  vertices = new List <Point>();
            List <double> zvalues  = _zValues == null ? null : new List <double>();
            List <double> mvalues  = _mValues == null ? null : new List <double>();

            for (int i = shapeIndex; i < nextShape; i++)
            {
                var s            = _shapes[i];
                var nextFigure   = i + 1 < _shapes.Length ? _shapes[i + 1].FigureOffset : _figures.Length;
                var figureOffset = figures.Count;
                for (int j = s.FigureOffset; j < nextFigure; j++)
                {
                    var f = _figures[j];
                    figures.Add(new Figure()
                    {
                        FigureAttribute = f.FigureAttribute, VertexOffset = vertices.Count
                    });
                    var nextFigureVertexOffset = (j + 1 < _figures.Length) ? _figures[j + 1].VertexOffset : _vertices.Length;
                    vertices.AddRange(_vertices.Skip(f.VertexOffset).Take(nextFigureVertexOffset - f.VertexOffset));
                    if (zvalues != null)
                    {
                        zvalues.AddRange(_zValues.Skip(f.VertexOffset).Take(nextFigureVertexOffset - f.VertexOffset));
                    }
                    if (mvalues != null)
                    {
                        mvalues.AddRange(_mValues.Skip(f.VertexOffset).Take(nextFigureVertexOffset - f.VertexOffset));
                    }
                }
                shapes.Add(new Shape()
                {
                    type = s.type, ParentOffset = shape.ParentOffset - s.ParentOffset - 1, FigureOffset = figureOffset
                });
            }
            geoDatum._shapes  = shapes.ToArray();
            geoDatum._figures = figures != null || figures.Any() ? figures?.ToArray() : null;
            if (vertices.Count == 1 && double.IsNaN(vertices[0].X) && double.IsNaN(vertices[0].Y)) //Empty point
            {
            }
            else
            {
                geoDatum._vertices = vertices.ToArray();
                geoDatum._zValues  = zvalues?.ToArray();
                geoDatum._mValues  = mvalues?.ToArray();
            }
            geoDatum._isLargerThanAHemisphere = this._isLargerThanAHemisphere;
            //TODO: Segments
            geoDatum._isValid = _isValid;
            return(geoDatum);
        }