Ejemplo n.º 1
0
 public static PointBag2 <double> ToGeom(PostgisMultiPoint geom)
 {
     if (geom != null)
     {
         return(factory.ConstructPointBag(Points(geom)));
     }
     return(null);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 1- Convert each coordinate from input PostGis MultiPoint
 /// 2- Create a NetTopology Multipoint with all coordinate converted from previous step.
 /// Throw ArgumentNullException if any of input marameter is null.
 /// </summary>
 /// <param name="geometry">a PostGisMultiPoint to convert. No restriction</param>
 /// <returns>NetTopology MultiPoint</returns>
 private static Geometry ProcessMultiPoint(PostgisMultiPoint geometry)
 {
     if (geometry != null)
     {
         //1-
         List <IPoint> arrpoints  = new List <IPoint>();
         int           pointCount = geometry.PointCount;
         for (int i = 0; i < pointCount; i++)
         {
             Coordinate2D iteri = geometry[i];
             arrpoints.Add(new Point(iteri.X, iteri.Y));
         }
         //2-
         return(new MultiPoint(arrpoints.ToArray()));
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
Ejemplo n.º 3
0
 public Task Write(PostgisMultiPoint value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
 => Write((PostgisGeometry)value, buf, lengthCache, parameter, async);
Ejemplo n.º 4
0
 public int ValidateAndGetLength(PostgisMultiPoint value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
 => value.GetLen(true);
Ejemplo n.º 5
0
        public override bool Read([CanBeNull] out PostgisGeometry result)
        {
            Contract.Assert(_inByteaMode != true);
            if (!_inByteaMode.HasValue)
            {
                _inByteaMode = false;
            }

            result = default(PostgisGeometry);
            if (_id == 0)
            {
                if (_readBuf.ReadBytesLeft < 5)
                {
                    return(false);
                }
                _bo = (ByteOrder)_readBuf.ReadByte();
                _id = _readBuf.ReadUInt32(_bo);
            }
            if (!_srid.HasValue)
            {
                if ((_id & (uint)EwkbModifier.HasSRID) != 0)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _srid = _readBuf.ReadUInt32(_bo);
                }
                else
                {
                    _srid = 0;
                }
            }

            switch ((WkbIdentifier)(_id & 7))
            {
            case WkbIdentifier.Point:
                _lastId = _id;
                if (_readBuf.ReadBytesLeft < 16)
                {
                    return(false);
                }
                result = new PostgisPoint(_readBuf.ReadDouble(_bo), _readBuf.ReadDouble(_bo))
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.LineString:
                _lastId = _id;
                if (_ipts == -1)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _points = new Coordinate2D[_readBuf.ReadInt32(_bo)];
                    _ipts   = 0;
                }
                for (; _ipts < _points.Length; _ipts++)
                {
                    if (_readBuf.ReadBytesLeft < 16)
                    {
                        return(false);
                    }
                    _points[_ipts] = new Coordinate2D(_readBuf.ReadDouble(_bo), _readBuf.ReadDouble(_bo));
                }
                result = new PostgisLineString(_points)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.Polygon:
                _lastId = _id;
                if (_irng == -1)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _rings = new Coordinate2D[_readBuf.ReadInt32(_bo)][];
                    _irng  = 0;
                }

                for (; _irng < _rings.Length; _irng++)
                {
                    if (_ipts == -1)
                    {
                        if (_readBuf.ReadBytesLeft < 4)
                        {
                            return(false);
                        }
                        _rings[_irng] = new Coordinate2D[_readBuf.ReadInt32(_bo)];
                        _ipts         = 0;
                    }
                    for (; _ipts < _rings[_irng].Length; _ipts++)
                    {
                        if (_readBuf.ReadBytesLeft < 16)
                        {
                            return(false);
                        }
                        _rings[_irng][_ipts] = new Coordinate2D(_readBuf.ReadDouble(_bo), _readBuf.ReadDouble(_bo));
                    }
                    _ipts = -1;
                }
                result = new PostgisPolygon(_rings)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.MultiPoint:
                _lastId = _id;
                if (_ipts == -1)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _points = new Coordinate2D[_readBuf.ReadInt32(_bo)];
                    _ipts   = 0;
                }
                for (; _ipts < _points.Length; _ipts++)
                {
                    if (_readBuf.ReadBytesLeft < 21)
                    {
                        return(false);
                    }
                    _readBuf.Skip(5);
                    _points[_ipts] = new Coordinate2D(_readBuf.ReadDouble(_bo), _readBuf.ReadDouble(_bo));
                }
                result = new PostgisMultiPoint(_points)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.MultiLineString:
                _lastId = _id;
                if (_irng == -1)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _rings = new Coordinate2D[_readBuf.ReadInt32(_bo)][];
                    _irng  = 0;
                }

                for (; _irng < _rings.Length; _irng++)
                {
                    if (_ipts == -1)
                    {
                        if (_readBuf.ReadBytesLeft < 9)
                        {
                            return(false);
                        }
                        _readBuf.Skip(5);
                        _rings[_irng] = new Coordinate2D[_readBuf.ReadInt32(_bo)];
                        _ipts         = 0;
                    }
                    for (; _ipts < _rings[_irng].Length; _ipts++)
                    {
                        if (_readBuf.ReadBytesLeft < 16)
                        {
                            return(false);
                        }
                        _rings[_irng][_ipts] = new Coordinate2D(_readBuf.ReadDouble(_bo), _readBuf.ReadDouble(_bo));
                    }
                    _ipts = -1;
                }
                result = new PostgisMultiLineString(_rings)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.MultiPolygon:
                _lastId = _id;
                if (_ipol == -1)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _pols = new Coordinate2D[_readBuf.ReadInt32(_bo)][][];
                    _ipol = 0;
                }

                for (; _ipol < _pols.Length; _ipol++)
                {
                    if (_irng == -1)
                    {
                        if (_readBuf.ReadBytesLeft < 9)
                        {
                            return(false);
                        }
                        _readBuf.Skip(5);
                        _pols[_ipol] = new Coordinate2D[_readBuf.ReadInt32(_bo)][];
                        _irng        = 0;
                    }
                    for (; _irng < _pols[_ipol].Length; _irng++)
                    {
                        if (_ipts == -1)
                        {
                            if (_readBuf.ReadBytesLeft < 4)
                            {
                                return(false);
                            }
                            _pols[_ipol][_irng] = new Coordinate2D[_readBuf.ReadInt32(_bo)];
                            _ipts = 0;
                        }
                        for (; _ipts < _pols[_ipol][_irng].Length; _ipts++)
                        {
                            if (_readBuf.ReadBytesLeft < 16)
                            {
                                return(false);
                            }
                            _pols[_ipol][_irng][_ipts] = new Coordinate2D(_readBuf.ReadDouble(_bo), _readBuf.ReadDouble(_bo));
                        }
                        _ipts = -1;
                    }
                    _irng = -1;
                }
                result = new PostgisMultiPolygon(_pols)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.GeometryCollection:
                PostgisGeometry[] g;
                int i;
                if (_icol.Count == 0)
                {
                    if (_readBuf.ReadBytesLeft < 4)
                    {
                        _lastId = _id;
                        return(false);
                    }
                    g = new PostgisGeometry[_readBuf.ReadInt32(_bo)];
                    i = 0;
                    if (_newGeom)     // We need to know whether we're in a nested geocoll or not.
                    {
                        _id      = 0;
                        _newGeom = false;
                    }
                    else
                    {
                        _id     = _lastId;
                        _lastId = 0;
                    }
                }
                else
                {
                    g = _geoms.Pop();
                    i = _icol.Pop();
                    if (_icol.Count == 0)
                    {
                        _id     = _lastId;
                        _lastId = 0;
                    }
                }
                for (; i < g.Length; i++)
                {
                    PostgisGeometry geom;

                    if (!Read(out geom))
                    {
                        _icol.Push(i);
                        _geoms.Push(g);
                        _id = (uint)WkbIdentifier.GeometryCollection;
                        return(false);
                    }
                    g[i] = geom;
                    Reset();
                }
                result = new PostgisGeometryCollection(g)
                {
                    SRID = _srid.Value
                };
                return(true);

            default:
                throw new InvalidOperationException("Unknown Postgis identifier.");
            }
        }
Ejemplo n.º 6
0
 public bool Read(out PostgisMultiPoint result) => ReadConcrete(out result);
Ejemplo n.º 7
0
 public Task Write(PostgisMultiPoint value, NpgsqlWriteBuffer buf, NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter, bool async, CancellationToken cancellationToken = default)
 => Write((PostgisGeometry)value, buf, lengthCache, parameter, async, cancellationToken);
Ejemplo n.º 8
0
        public bool Read(out PostgisGeometry result)
        {
            result = default(PostgisGeometry);
            if (_id == 0)
            {
                if (_buf.ReadBytesLeft < 5)
                {
                    return(false);
                }
                _bo = (ByteOrder)_buf.ReadByte();
                _id = _buf.ReadUInt32(_bo);
            }
            if (!_srid.HasValue)
            {
                if ((_id & (uint)EwkbModifier.HasSRID) != 0)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _srid = _buf.ReadUInt32(_bo);
                }
                else
                {
                    _srid = 0;
                }
            }

            switch ((WkbIdentifier)(_id & (uint)7))
            {
            case WkbIdentifier.Point:
                if (_buf.ReadBytesLeft < 16)
                {
                    return(false);
                }
                result = new PostgisPoint(_buf.ReadDouble(_bo), _buf.ReadDouble(_bo))
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.LineString:
                if (_ipts == -1)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _points = new Coordinate2D[_buf.ReadInt32(_bo)];
                    _ipts   = 0;
                }
                for (; _ipts < _points.Length; _ipts++)
                {
                    if (_buf.ReadBytesLeft < 16)
                    {
                        return(false);
                    }
                    _points[_ipts] = new Coordinate2D(_buf.ReadDouble(_bo), _buf.ReadDouble(_bo));
                }
                result = new PostgisLineString(_points)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.Polygon:
                if (_irng == -1)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _rings = new Coordinate2D[_buf.ReadInt32(_bo)][];
                    _irng  = 0;
                }

                for (; _irng < _rings.Length; _irng++)
                {
                    if (_ipts == -1)
                    {
                        if (_buf.ReadBytesLeft < 4)
                        {
                            return(false);
                        }
                        _rings[_irng] = new Coordinate2D[_buf.ReadInt32(_bo)];
                        _ipts         = 0;
                    }
                    for (; _ipts < _rings[_irng].Length; _ipts++)
                    {
                        if (_buf.ReadBytesLeft < 16)
                        {
                            return(false);
                        }
                        _rings[_irng][_ipts] = new Coordinate2D(_buf.ReadDouble(_bo), _buf.ReadDouble(_bo));
                    }
                    _ipts = -1;
                }
                result = new PostgisPolygon(_rings)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.MultiPoint:
                if (_ipts == -1)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _points = new Coordinate2D[_buf.ReadInt32(_bo)];
                    _ipts   = 0;
                }
                for (; _ipts < _points.Length; _ipts++)
                {
                    if (_buf.ReadBytesLeft < 21)
                    {
                        return(false);
                    }
                    _buf.Skip(5);
                    _points[_ipts] = new Coordinate2D(_buf.ReadDouble(_bo), _buf.ReadDouble(_bo));
                }
                result = new PostgisMultiPoint(_points)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.MultiLineString:
                if (_irng == -1)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _rings = new Coordinate2D[_buf.ReadInt32(_bo)][];
                    _irng  = 0;
                }

                for (; _irng < _rings.Length; _irng++)
                {
                    if (_ipts == -1)
                    {
                        if (_buf.ReadBytesLeft < 9)
                        {
                            return(false);
                        }
                        _buf.Skip(5);
                        _rings[_irng] = new Coordinate2D[_buf.ReadInt32(_bo)];
                        _ipts         = 0;
                    }
                    for (; _ipts < _rings[_irng].Length; _ipts++)
                    {
                        if (_buf.ReadBytesLeft < 16)
                        {
                            return(false);
                        }
                        _rings[_irng][_ipts] = new Coordinate2D(_buf.ReadDouble(_bo), _buf.ReadDouble(_bo));
                    }
                    _ipts = -1;
                }
                result = new PostgisMultiLineString(_rings)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.MultiPolygon:
                if (_ipol == -1)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _pols = new Coordinate2D[_buf.ReadInt32(_bo)][][];
                    _ipol = 0;
                }

                for (; _ipol < _pols.Length; _ipol++)
                {
                    if (_irng == -1)
                    {
                        if (_buf.ReadBytesLeft < 9)
                        {
                            return(false);
                        }
                        _buf.Skip(5);
                        _pols[_ipol] = new Coordinate2D[_buf.ReadInt32(_bo)][];
                        _irng        = 0;
                    }
                    for (; _irng < _pols[_ipol].Length; _irng++)
                    {
                        if (_ipts == -1)
                        {
                            if (_buf.ReadBytesLeft < 4)
                            {
                                return(false);
                            }
                            _pols[_ipol][_irng] = new Coordinate2D[_buf.ReadInt32(_bo)];
                            _ipts = 0;
                        }
                        for (; _ipts < _pols[_ipol][_irng].Length; _ipts++)
                        {
                            if (_buf.ReadBytesLeft < 16)
                            {
                                return(false);
                            }
                            _pols[_ipol][_irng][_ipts] = new Coordinate2D(_buf.ReadDouble(_bo), _buf.ReadDouble(_bo));
                        }
                        _ipts = -1;
                    }
                    _irng = -1;
                }
                result = new PostgisMultiPolygon(_pols)
                {
                    SRID = _srid.Value
                };
                return(true);

            case WkbIdentifier.GeometryCollection:
                if (_newGeom)
                {
                    if (_buf.ReadBytesLeft < 4)
                    {
                        return(false);
                    }
                    _geoms.Push(new PostgisGeometry[_buf.ReadInt32(_bo)]);
                    _icol.Push(new Counter());
                }
                _id = 0;
                var g = _geoms.Peek();
                var i = _icol.Peek();
                for (; i < g.Length; i.Increment())
                {
                    PostgisGeometry geom;
                    if (!Read(out geom))
                    {
                        _newGeom = false;
                        return(false);
                    }
                    g[i] = geom;
                    Reset();
                }
                result = new PostgisGeometryCollection(g)
                {
                    SRID = _srid.Value
                };
                _geoms.Pop();
                _icol.Pop();
                return(true);

            default:
                throw new InvalidOperationException("Unknown Postgis identifier.");
            }
        }