Beispiel #1
0
        public void SubGeometriesWithSRID()
        {
            var point = new PostgisPoint(1, 1)
            {
                SRID = 4326
            };

            var lineString = new PostgisLineString(new[] { new Coordinate2D(2, 2), new Coordinate2D(3, 3) })
            {
                SRID = 4326
            };

            var polygon = new PostgisPolygon(new[] { new[] { new Coordinate2D(4, 4), new Coordinate2D(5, 5), new Coordinate2D(6, 6), new Coordinate2D(4, 4) } })
            {
                SRID = 4326
            };

            var collection = new PostgisGeometryCollection(new PostgisGeometry[] { point, lineString, polygon })
            {
                SRID = 4326
            };

            using (var conn = OpenConnection())
                using (var cmd = new NpgsqlCommand("SELECT :p", conn))
                {
                    cmd.Parameters.AddWithValue("p", collection);
                    cmd.ExecuteNonQuery();
                }
        }
Beispiel #2
0
 internal PostgisMultiLineString(Coordinate2D[][] pointArray)
 {
     _lineStrings = new PostgisLineString[pointArray.Length];
     for (var i = 0; i < pointArray.Length; i++)
     {
         _lineStrings[i] = new PostgisLineString(pointArray[i]);
     }
 }
 public SpatialInformation(Int64 TripId, Int64 EntryId, GeoCoordinate MPoint, double DistanceToLag, PostgisLineString PathLine)
 {
     this.TripId = TripId;
     this.EntryId = EntryId;
     this.MPoint = MPoint;
     this.DistanceToLag = DistanceToLag;
     this.PathLine = PathLine;
 }
Beispiel #4
0
 public static Polyline2 <double> ToGeom(PostgisLineString geom)
 {
     if (geom != null)
     {
         return(factory.ConstructPolyline(Points(geom)));
     }
     return(null);
 }
 public SegmentInformation(Int64 SegmentId, Int64 OSMId, string RoadName, Int16 RoadType, Int16 Oneway, Int16 Bridge, Int16 Tunnel, Int16 MaxSpeed, bool Direction, PostgisLineString RoadLine)
 {
     this.SegmentId = SegmentId;
     this.OSMId = OSMId;
     this.RoadName = RoadName;
     this.RoadType = RoadType;
     this.Oneway = Oneway;
     this.Bridge = Bridge;
     this.Tunnel = Tunnel;
     this.MaxSpeed = MaxSpeed;
     this.Direction = Direction;
     this.RoadLine = RoadLine;
 }
        public void TestPostGisMultiLineStringReturnMultiLineStringWithCoordinatesAndSRS()
        {
            StubFieldValueGetter valueGetter = new StubFieldValueGetter();

            valueGetter.OrdinalToStub = 0;
            valueGetter.FieldCount    = 1;
            Coordinate2D[]    coords1 = new Coordinate2D[] { new Coordinate2D(_X1, _Y1), new Coordinate2D(_X2, _Y2), new Coordinate2D(_X3, _Y3) };
            Coordinate2D[]    coords2 = new Coordinate2D[] { new Coordinate2D(_X4, _Y4), new Coordinate2D(_X5, _Y5), new Coordinate2D(_X6, _Y6) };
            PostgisLineString pgLS1   = new PostgisLineString(coords1);
            PostgisLineString pgLS2   = new PostgisLineString(coords2);

            valueGetter.GeometryToStub      = new PostgisMultiLineString(new PostgisLineString[] { pgLS1, pgLS2 });
            valueGetter.GeometryToStub.SRID = _SRID;
            Geometry geomResult = HRConverterPostGisToNetTopologySuite.ConvertFrom(valueGetter);

            Assert.NotNull(geomResult);
            Assert.IsType <MultiLineString>(geomResult);
            MultiLineString multiLineStringResult = (MultiLineString)geomResult;

            Assert.Equal(2, multiLineStringResult.NumGeometries);
            LineString ls1 = (LineString)multiLineStringResult[0];

            Assert.Equal(3, ls1.NumPoints);
            LineString ls2 = (LineString)multiLineStringResult[1];

            Assert.Equal(3, ls2.NumPoints);
            Assert.Equal(3, ls1.Coordinates.Length);
            Assert.Equal(_X1, ls1.Coordinates[0].X);
            Assert.Equal(_Y1, ls1.Coordinates[0].Y);
            Assert.Equal(_X2, ls1.Coordinates[1].X);
            Assert.Equal(_Y2, ls1.Coordinates[1].Y);
            Assert.Equal(_X3, ls1.Coordinates[2].X);
            Assert.Equal(_Y3, ls1.Coordinates[2].Y);
            Assert.Equal(_SRID, ls1.SRID);
            Assert.Equal(3, ls2.Coordinates.Length);
            Assert.Equal(_X4, ls2.Coordinates[0].X);
            Assert.Equal(_Y4, ls2.Coordinates[0].Y);
            Assert.Equal(_X5, ls2.Coordinates[1].X);
            Assert.Equal(_Y5, ls2.Coordinates[1].Y);
            Assert.Equal(_X6, ls2.Coordinates[2].X);
            Assert.Equal(_Y6, ls2.Coordinates[2].Y);
            Assert.Equal(_SRID, ls2.SRID);
        }
Beispiel #7
0
        /// <summary>
        /// 1- Convert each Coordinate of PostGisLineString int NetTopology Coordinate.
        /// 2- Create NetTopologyLineString with all Coordinates from previous step.
        /// Throw ArgumentNullException if any of input marameter is null.
        /// </summary>
        /// <param name="geometry">a PostgisLineString. No restriction.</param>
        /// <returns>a NetTopology LineString</returns>
        private static Geometry ProcessLineString(PostgisLineString geometry)
        {
            if (geometry != null)
            {
                //1-
                int          pointCount = geometry.PointCount;
                Coordinate[] coords     = new Coordinate[pointCount];

                for (int i = 0; i < pointCount; i++)
                {
                    Coordinate2D coord2D = geometry[i];
                    coords[i]   = new Coordinate();
                    coords[i].X = coord2D.X;
                    coords[i].Y = coord2D.Y;
                }
                //2-
                return(new LineString(coords));
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Beispiel #8
0
 public Task Write(PostgisLineString value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
 => Write((PostgisGeometry)value, buf, lengthCache, parameter, async);
Beispiel #9
0
 public int ValidateAndGetLength(PostgisLineString value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
 => value.GetLen(true);
Beispiel #10
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.");
            }
        }
 public SpatialInformation(GeoCoordinate MPoint, double DistanceToLag, PostgisLineString PathLine)
 {
     this.MPoint = MPoint;
     this.DistanceToLag = DistanceToLag;
     this.PathLine = PathLine;
 }
 public bool Read(out PostgisLineString result) => ReadConcrete(out result);
Beispiel #13
0
 public Task Write(PostgisLineString value, NpgsqlWriteBuffer buf, NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter, bool async, CancellationToken cancellationToken = default)
 => Write((PostgisGeometry)value, buf, lengthCache, parameter, async, cancellationToken);
Beispiel #14
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.");
            }
        }