예제 #1
0
 public static Geometry Boundary(Geometry g, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg         = SqlGeometryConverter.ToSqlGeometry(g);
         SqlGeometry sgBoundary = sg.STBoundary();
         return(SqlGeometryConverter.ToSharpMapGeometry(sgBoundary));
     }
     else
     {
         throw new ArgumentOutOfRangeException("Geography does not support STBoundary");
     }
 }
예제 #2
0
 /// <summary>
 /// Returns true if otherGeometry is disjoint from the source geometry.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static bool Disjoint(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         return(!g2.Intersects(g1));
     }
     else
     {
         SqlGeography sg1 = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2 = SqlGeographyConverter.ToSqlGeography(g2);
         return((bool)sg1.STDisjoint(sg2));
     }
 }
예제 #3
0
        public void TestGetGeometriesInViewFORCEINDEX(SqlServerSpatialObjectType spatialType, string indexName, bool validateGeometries)
        {
            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(spatialType);

            sq.ForceIndex         = indexName;
            sq.ValidateGeometries = validateGeometries;

            var geometries = sq.GetGeometriesInView(GetTestEnvelope(spatialType));

            Assert.IsNotNull(geometries);
            // NOTE ValidateGeometries is ignored when using ForceIndex
            Assert.AreEqual(_numValidGeoms, geometries.Count);
        }
예제 #4
0
 /// <summary>
 /// Returns true if the only points in common between the two geometries lie in the union of their boundaries.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static bool Touches(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)sg1.STTouches(sg2));
     }
     else
     {
         throw new ArgumentOutOfRangeException("Geography does not support STTouches. You must first convert Geography to Geometry using WKB");
     }
 }
예제 #5
0
 /// <summary>
 /// Computes a buffer around <paramref name="g"/> with a given <paramref name="distance"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g">A geometry/geography</param>
 /// <param name="distance">A distance</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g"/> is a geometry or geography objects</param>
 /// <returns>The buffered geometry</returns>
 public static Geometry Buffer(Geometry g, Double distance, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg       = SqlGeometryConverter.ToSqlGeometry(g);
         SqlGeometry sgBuffer = sg.STBuffer(distance);
         return(SqlGeometryConverter.ToSharpMapGeometry(sgBuffer));
     }
     else
     {
         SqlGeography sg       = SqlGeographyConverter.ToSqlGeography(g);
         SqlGeography sgBuffer = sg.STBuffer(distance);
         return(SqlGeographyConverter.ToSharpMapGeometry(sgBuffer));
     }
 }
예제 #6
0
        public void TestExecuteIntersectionQueryAllHints(SqlServerSpatialObjectType spatialType, string indexName, bool validateGeometries)
        {
            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(spatialType);

            sq.NoLockHint         = true;
            sq.ForceSeekHint      = true;
            sq.ForceIndex         = indexName;
            sq.ValidateGeometries = validateGeometries;

            SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

            sq.ExecuteIntersectionQuery(GetTestEnvelope(spatialType), ds);
            // Note: ValidateGeometries ignored when using ForceSeek or ForceIndex
            Assert.AreEqual(_numValidGeoms, ds.Tables[0].Rows.Count);
        }
예제 #7
0
 /// <summary>
 /// Returns true if the primary geometry is wholly contained within the comparison geometry.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static bool Within(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)sg1.STWithin(sg2));
     }
     else
     {
         SqlGeography sg1 = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2 = SqlGeographyConverter.ToSqlGeography(g2);
         return((bool)sg1.STWithin(sg2));
     }
 }
예제 #8
0
 /// <summary>
 /// Computes the convex-hull of <paramref name="g"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g">A geometry/geography</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g"/> is geometry or geography</param>
 /// <returns>The convex-hull</returns>
 public static Geometry ConvexHull(Geometry g, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg           = SqlGeometryConverter.ToSqlGeometry(g);
         SqlGeometry sgConvexHull = sg.STConvexHull();
         return(SqlGeometryConverter.ToSharpMapGeometry(sgConvexHull));
     }
     else
     {
         SqlGeography sg           = SqlGeographyConverter.ToSqlGeography(g);
         SqlGeography sgConvexHull = sg.STConvexHull();
         return(SqlGeographyConverter.ToSharpMapGeometry(sgConvexHull));
     }
 }
예제 #9
0
 /// <summary>
 /// Returns true if otherGeometry is wholly contained within the source geometry. This is the same as
 /// reversing the primary and comparison shapes of the Within operation.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns>True if otherGeometry is wholly contained within the source geometry.</returns>
 public static bool Contains(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == Data.Providers.SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)(sg1.STContains(sg2)));
     }
     else
     {
         SqlGeography sg1 = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2 = SqlGeographyConverter.ToSqlGeography(g2);
         return((bool)(sg1.STContains(sg2)));
     }
 }
예제 #10
0
        //[NUnit.Framework.TestCase(SqlServerSpatialObjectType.Geography, false)]
        //[NUnit.Framework.TestCase(SqlServerSpatialObjectType.Geography, true)]
        public void TestGetGeometriesInViewEx(SqlServerSpatialObjectType spatialType, bool validateGeometries)
        {
            // Note:
            // This test may fail with an InvalidCastException. This is caused by multiple versions of the
            // Microsoft.SqlServer.Types assembly being available (e.g. SQL 2008 and 2012).
            // This can be solved with a <bindingRedirect> in the .config file.
            // http://connect.microsoft.com/SQLServer/feedback/details/685654/invalidcastexception-retrieving-sqlgeography-column-in-ado-net-data-reader

            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProviderEx();
            sq.ValidateGeometries = validateGeometries;

            var geometries = sq.GetGeometriesInView(GetTestEnvelope(spatialType));

            Assert.IsNotNull(geometries);
            Assert.AreEqual(validateGeometries ? _numValidatedGeoms : _numValidGeoms, geometries.Count);
        }
예제 #11
0
 /// <summary>
 /// Computes the intersection of <paramref name="g1"/> and <paramref name="g2"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g1">A geometry/geography</param>
 /// <param name="g2">A geometry/geography</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g1"/> and <paramref name="g2"/> are geometry or geography objects</param>
 /// <returns>The intersection</returns>
 public static Geometry Intersection(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1            = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2            = SqlGeometryConverter.ToSqlGeometry(g2);
         SqlGeometry sgIntersection = sg1.STIntersection(sg2);
         return(SqlGeometryConverter.ToSharpMapGeometry(sgIntersection));
     }
     else
     {
         SqlGeography sg1            = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2            = SqlGeographyConverter.ToSqlGeography(g2);
         SqlGeography sgIntersection = sg1.STIntersection(sg2);
         return(SqlGeographyConverter.ToSharpMapGeometry(sgIntersection));
     }
 }
예제 #12
0
 /// <summary>
 /// Computes the symmetric-difference of <paramref name="g1"/> and <paramref name="g2"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g1">A geometry/geography</param>
 /// <param name="g2">A geometry/geography</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g1"/> and <paramref name="g2"/> are geometry or geography objects</param>
 /// <returns>The symmetric difference</returns>
 public static Geometry SymDifference(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1             = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2             = SqlGeometryConverter.ToSqlGeometry(g2);
         SqlGeometry sgSymDifference = sg1.STSymDifference(sg2);
         return(SqlGeometryConverter.ToSharpMapGeometry(sgSymDifference));
     }
     else
     {
         SqlGeography sg1             = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2             = SqlGeographyConverter.ToSqlGeography(g2);
         SqlGeography sgSymDifference = sg1.STSymDifference(sg2);
         return(SqlGeographyConverter.ToSharpMapGeometry(sgSymDifference));
     }
 }
예제 #13
0
        public void TestGetExtentsSpatialIndex(SqlServerSpatialObjectType spatialType)
        {
            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(spatialType);

            if (spatialType == SqlServerSpatialObjectType.Geography)
            {
                var ex = Assert.Throws <ArgumentOutOfRangeException>(() =>
                {
                    sq.ExtentsMode = SharpMap.Data.Providers.SqlServer2008ExtentsMode.SpatialIndex;
                });
            }
            else
            {
                sq.ExtentsMode = SharpMap.Data.Providers.SqlServer2008ExtentsMode.SpatialIndex;
                GeoAPI.Geometries.Envelope extents = sq.GetExtents();

                Assert.IsNotNull(extents);
            }
        }
예제 #14
0
        public void TestSqlServer2008(SqlServerSpatialObjectType spatialType)
        {
            var sql2008S = new SqlServer2008("Data Source=IVV-SQLD; Database=OBE;Integrated Security=SSPI;",
                                             "roads", "spatialCol", "idCol",
                                             spatialType,
                                             4326,
                                             SqlServer2008ExtentsMode.EnvelopeAggregate);

            var sql2008D = SandD(sql2008S, GetFormatter());

            Assert.AreEqual(sql2008S.ConnectionString, sql2008D.ConnectionString);
            Assert.AreEqual(sql2008S.Table, sql2008D.Table);
            Assert.AreEqual(sql2008S.TableSchema, sql2008D.TableSchema);
            Assert.AreEqual(sql2008S.GeometryColumn, sql2008D.GeometryColumn);
            Assert.AreEqual(sql2008S.ObjectIdColumn, sql2008D.ObjectIdColumn);
            Assert.AreEqual(sql2008S.SpatialObjectType, sql2008D.SpatialObjectType);
            Assert.AreEqual(sql2008S.SRID, sql2008D.SRID);
            Assert.AreEqual(sql2008S.ExtentsMode, sql2008D.ExtentsMode);
        }
예제 #15
0
        /// <summary>
        /// Initializes a new connection to SQL Server
        /// </summary>
        /// <param name="connectionStr">Connectionstring</param>
        /// <param name="tablename">Name of data table</param>
        /// <param name="geometryColumnName">Name of geometry column</param>
        /// <param name="oidColumnName">Name of column with unique identifier</param>
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType, bool useSpatialIndexExtentAsExtent)
        {
            ConnectionString   = connectionStr;
            Table              = tablename;
            GeometryColumn     = geometryColumnName;
            ObjectIdColumn     = oidColumnName;
            _spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
            case SqlServerSpatialObjectType.Geometry:
                _spatialObject = "geometry";
                break;

            //case SqlServerSpatialObjectType.Geography:
            default:
                _spatialObject = "geography";
                break;
            }

            _UseSpatialIndexExtentAsExtent = useSpatialIndexExtentAsExtent;
        }
예제 #16
0
        /// <summary>
        /// Initializes a new connection to SQL Server
        /// </summary>
        /// <param name="connectionStr">Connectionstring</param>
        /// <param name="tablename">Name of data table</param>
        /// <param name="geometryColumnName">Name of geometry column</param>
        /// <param name="oidColumnName">Name of column with unique identifier</param>
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType, bool useSpatialIndexExtentAsExtent)
        {
            ConnectionString   = connectionStr;
            Table              = tablename;
            GeometryColumn     = geometryColumnName;
            ObjectIdColumn     = oidColumnName;
            _spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
            case SqlServerSpatialObjectType.Geometry:
                _spatialObject = "geometry";
                break;

            //case SqlServerSpatialObjectType.Geography:
            default:
                _spatialObject = "geography";
                break;
            }

            _ExtentsMode = (useSpatialIndexExtentAsExtent ? SqlServer2008ExtentsMode.SpatialIndex : SqlServer2008ExtentsMode.QueryIndividualFeatures);
        }
예제 #17
0
 /// <summary>
 /// Computes the union of <paramref name="g"/> and <paramref name="geometries"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g">A geometry/geography</param>
 /// <param name="geometries">A (series of) geometry/geography objects</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g"/> and <paramref name="geometries"/> are geometry or geography objects</param>
 /// <returns>The union</returns>
 public static Geometry Union(Geometry g, SqlServerSpatialObjectType spatialMode, params Geometry[] geometries)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g);
         foreach (SqlGeometry sgUnion in SqlGeometryConverter.ToSqlGeometries(geometries))
         {
             sg = sg.STUnion(sgUnion);
         }
         return(SqlGeometryConverter.ToSharpMapGeometry(sg));
     }
     else
     {
         SqlGeography sg = SqlGeographyConverter.ToSqlGeography(g);
         foreach (SqlGeography sgUnion in SqlGeographyConverter.ToSqlGeographies(geometries))
         {
             sg = sg.STUnion(sgUnion);
         }
         return(SqlGeographyConverter.ToSharpMapGeometry(sg));
     }
 }
예제 #18
0
        /// <summary>
        /// Initializes a new connection to SQL Server
        /// </summary>
        /// <param name="connectionStr">Connectionstring</param>
        /// <param name="tablename">Name of data table</param>
        /// <param name="geometryColumnName">Name of geometry column</param>
        /// <param name="oidColumnName">Name of column with unique identifier</param>
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName,
                             string geometryLabelName, SqlServerSpatialObjectType spatialObjectType, int srid)
        {
            this.ConnectionString   = connectionStr;
            this.Table              = tablename;
            this.GeometryColumn     = geometryColumnName;
            this.ObjectIdColumn     = oidColumnName;
            this.GeometryLabel      = geometryColumnName;
            this._spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
            case SqlServerSpatialObjectType.Geometry:
                this._spatialObject = "geometry";
                break;

            default:
                this._spatialObject = "geography";
                break;
            }

            this.SRID = srid;
        }
예제 #19
0
        private IGeometry ToSqlServerAndBack(IGeometry gIn, SqlServerSpatialObjectType spatialType)
        {
            Assert.That(gIn, Is.Not.Null);
            //Assert.That(gIn.SRID, Is.EqualTo(-1));
            //gIn.SRID = 0;
            Assert.That(gIn.SRID, Is.GreaterThan(0));

            switch (spatialType)
            {
            case SqlServerSpatialObjectType.Geography:
                SqlGeography sqlGeography = SqlGeographyConverter.ToSqlGeography(gIn);
                //if (gIn is NetTopologySuite.Geometries.Polygon || gIn is NetTopologySuite.Geometries.MultiPolygon)
                //{
                //    sqlGeography.ReorientObject().MakeValid();
                //}
                return(SqlGeographyConverter.ToSharpMapGeometry(sqlGeography, new NetTopologySuite.Geometries.GeometryFactory()));

            default:
                SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn);
                return(SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry, new NetTopologySuite.Geometries.GeometryFactory()));
            }
        }
예제 #20
0
        public void Operations(SqlServerSpatialObjectType spatialType, double bufferDist)
        {
            int srid = (spatialType == SqlServerSpatialObjectType.Geometry ? 0 : 4326);

            //Prepare data
            var gPn = GeometryFromWKT.Parse(Point);

            gPn.SRID = srid;
            var gMp = GeometryFromWKT.Parse(Multipoint);

            gMp.SRID = srid;
            var gLi = GeometryFromWKT.Parse(Linestring);

            gLi.SRID = srid;
            var gML = GeometryFromWKT.Parse(MultiLinestring);

            gML.SRID = srid;
            var gPl = GeometryFromWKT.Parse(Polygon);

            gPl.SRID = srid;

            System.Diagnostics.Trace.WriteLine(spatialType.ToString());
            if (spatialType == SqlServerSpatialObjectType.Geography)
            {
                System.Diagnostics.Trace.WriteLine("SqlServer syntax (STGeomFromText does not require .ReorientObject()):  SELECT geography::STGeomFromText(' insert WKT '), 4326)");
            }

            var gPnBuffer30 = SpatialOperationsEx.Buffer(gPn, bufferDist, spatialType);

            System.Diagnostics.Trace.WriteLine(gPnBuffer30.ToString());

            var gPnBuffer30IntersectiongPl = SpatialOperationsEx.Intersection(gPnBuffer30, gPl, spatialType);

            System.Diagnostics.Trace.WriteLine(gPnBuffer30IntersectiongPl.ToString());

            var gUnion = SpatialOperationsEx.Union(gPn, spatialType, gMp, gML, gLi, gPl);

            System.Diagnostics.Trace.WriteLine(gUnion.ToString());
        }
예제 #21
0
        public void TestShapeFile(SqlServerSpatialObjectType spatialType)
        {
            using (var p = new ShapeFile(TestUtility.GetPathToTestFile("SPATIAL_F_SKARVMUFF.shp"), true))
            {
                p.Open();

                var env = p.GetExtents();
                if (spatialType == SqlServerSpatialObjectType.Geography && (env.MaxY > 90 || env.MaxY < -90))
                {
                    Assert.Ignore("Test file Y values exceed valid latitudes");
                }

                for (uint i = 0; i < p.GetFeatureCount(); i++)
                {
                    var fdr = p.GetFeature(i);
                    if (fdr.Geometry == null)
                    {
                        continue;
                    }

                    try
                    {
                        fdr.Geometry.SRID = 4326;
                        var res = ToSqlServerAndBack(fdr.Geometry, spatialType);
                        Assert.AreEqual(fdr.Geometry, res);
                        System.Diagnostics.Trace.WriteLine(string.Format("Feature {0} ({1}) converted!", i, fdr[0]));
                    }
                    catch (SqlGeometryConverterException)
                    {
                        System.Diagnostics.Trace.WriteLine(string.Format("Feature {0} ({1}) conversion failed!", i, fdr[0]));
                    }
                    catch (SqlGeographyConverterException)
                    {
                        System.Diagnostics.Trace.WriteLine(string.Format("Feature {0} ({1}) conversion failed!", i, fdr[0]));
                    }
                }
            }
        }
예제 #22
0
        public void TestGetExtentsEnvelopeAggregate(SqlServerSpatialObjectType spatialType)
        {
            using (SqlConnection conn = new SqlConnection(UnitTests.Properties.Settings.Default.SqlServer2008))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT SERVERPROPERTY('productversion')";
                    string productversion = (string)cmd.ExecuteScalar();
                    if (Version.Parse(productversion).Major < 11)
                    {
                        Assert.Ignore("Requires SQL Server 2012 connection");
                    }
                }
            }

            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(spatialType);

            sq.ExtentsMode = SharpMap.Data.Providers.SqlServer2008ExtentsMode.EnvelopeAggregate;
            GeoAPI.Geometries.Envelope extents = sq.GetExtents();

            Assert.IsNotNull(extents);
        }
예제 #23
0
        /// <summary>
        /// Initializes a new connection to SQL Server
        /// </summary>
        /// <param name="connectionStr">Connectionstring</param>
        /// <param name="tablename">Name of data table</param>
        /// <param name="spatialColumnName">Name of spatial column</param>
        /// <param name="oidColumnName">Name of column with unique identifier</param>
        /// <param name="spatialObjectType">spatial type (Geometry or Geography)</param>
        /// <param name="srid">The spatial reference id</param>
        /// <param name="extentsMode">Mode for calculating full extents of the data</param>
        public SqlServer2008(string connectionStr, string tablename, string spatialColumnName, string oidColumnName,
                             SqlServerSpatialObjectType spatialObjectType, int srid, SqlServer2008ExtentsMode extentsMode)
        {
            ConnectionString = connectionStr;

            ParseTablename(tablename);

            GeometryColumn    = spatialColumnName;
            ObjectIdColumn    = oidColumnName;
            SpatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
            case SqlServerSpatialObjectType.Geometry:
                _spatialTypeString = "geometry";
                _reorientObject    = string.Empty;
                break;

            //case SqlServerSpatialObjectType.Geography:
            default:
                _spatialTypeString = "geography";
                _reorientObject    = ".ReorientObject()";
                break;
            }

            SRID = srid;

            ExtentsMode = extentsMode;

            if (!string.IsNullOrEmpty(TableSchema))
            {
                QualifiedTable = $"[{TableSchema}].[{Table}]";
            }
            else
            {
                QualifiedTable = $"[{Table}]";
            }
        }
        /// <summary>
        /// Initializes a new connection to SQL Server
        /// </summary>
        /// <param name="connectionStr">Connectionstring</param>
        /// <param name="tablename">Name of data table</param>
        /// <param name="geometryColumnName">Name of geometry column</param>
        /// <param name="oidColumnName">Name of column with unique identifier</param>
        //public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName) :
        //    this(connectionStr, tablename, geometryColumnName, oidColumnName, SqlServerSpatialObjectType.Geometry) { }

        /// <summary>
        /// Initializes a new connection to SQL Server
        /// </summary>
        /// <param name="connectionStr">Connectionstring</param>
        /// <param name="tablename">Name of data table</param>
        /// <param name="geometryColumnName">Name of geometry column</param>
        /// <param name="oidColumnName">Name of column with unique identifier</param>
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
        /// <param name="SRID">The spatial reference id</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName,
                             SqlServerSpatialObjectType spatialObjectType,
                             //bool useSpatialIndexExtentAsExtent,
                             int SRID)
        {
            this.ConnectionString  = connectionStr;
            this.Table             = tablename;
            this.GeometryColumn    = geometryColumnName;
            this.ObjectIdColumn    = oidColumnName;
            this.spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
            case SqlServerSpatialObjectType.Geometry:
                this.spatialObject = "geometry";
                break;

            default:
                this.spatialObject = "geography";
                break;
            }

            //_extentsMode = (useSpatialIndexExtentAsExtent ? SqlServer2008ExtentsMode.SpatialIndex : SqlServer2008ExtentsMode.QueryIndividualFeatures);
            this.SRID = SRID;
        }
예제 #25
0
        private SharpMap.Data.Providers.SqlServer2008 GetTestProvider(SqlServerSpatialObjectType spatialType)
        {
            switch (spatialType)
            {
            case SqlServerSpatialObjectType.Geography:
                // NB note forcing WGS84
                return(new SharpMap.Data.Providers.SqlServer2008(UnitTests.Properties.Settings.Default.SqlServer2008,
                                                                 "roads_ugl_geog", "GEOG", "ID", spatialType, GeographySrid, SqlServer2008ExtentsMode.QueryIndividualFeatures)
                {
                    //ValidateGeometries = true
                    //,
                    //DefinitionQuery = "ID NOT IN (103)" // Invalid Geom
                });

            default:
                return(new SharpMap.Data.Providers.SqlServer2008(UnitTests.Properties.Settings.Default.SqlServer2008,
                                                                 "roads_ugl_geom", "GEOM", "ID", spatialType)
                {
                    //ValidateGeometries = true
                    //,
                    //DefinitionQuery = "ID NOT IN (103)"  // Invalid Geom
                });
            }
        }
예제 #26
0
        public void TestExecuteIntersectionQueryExceedGeogMaxExtents(SqlServerProviderMode providerMode, SqlServerSpatialObjectType spatialType,
                                                                     double x1, double x2, double y1, double y2)
        {
            // occurs when user zooms out beyond map extents. For Geog, when latitude approaches 90 N or S can result in
            // error 24206: "The specified input cannot be accepted because it contains an edge with antipodal points."
            // Longitudes exceeding -179.99999999 or 180.0 are "wrapped" resulting in unexpected polygon (also contributes to err 24206)
            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(providerMode, spatialType);

            SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

            sq.ExecuteIntersectionQuery(new GeoAPI.Geometries.Envelope(x1, x2, y1, y2), ds);

            Assert.AreEqual(sq.ValidateGeometries ? _numValidatedGeoms : _numValidGeoms, ds.Tables[0].Rows.Count);
        }
예제 #27
0
 /// <summary>
 /// Initializes a new connection to SQL Server
 /// </summary>
 /// <param name="connectionStr">Connectionstring</param>
 /// <param name="tablename">Name of data table</param>
 /// <param name="oidColumnName">Name of column with unique identifier</param>
 /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
 public SqlServer2008(string connectionStr, string tablename, string oidColumnName, string geometryLabelName,
                      SqlServerSpatialObjectType spatialObjectType, int srid) :
     this(connectionStr, tablename, "shape", oidColumnName, geometryLabelName, spatialObjectType, srid)
 {
 }
예제 #28
0
 /// <summary>   
 /// Initializes a new connection to SQL Server   
 /// </summary>   
 /// <param name="connectionStr">Connectionstring</param>   
 /// <param name="tablename">Name of data table</param>   
 /// <param name="oidColumnName">Name of column with unique identifier</param>
 /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
 public SqlServer2008(string connectionStr, string tablename, string oidColumnName, SqlServerSpatialObjectType spatialObjectType)
     : this(connectionStr,tablename,"shape",oidColumnName, spatialObjectType)
 {
 }
예제 #29
0
		/// <summary>   
        /// Initializes a new connection to SQL Server   
        /// </summary>   
        /// <param name="connectionStr">Connectionstring</param>   
        /// <param name="tablename">Name of data table</param>   
        /// <param name="geometryColumnName">Name of geometry column</param>   
        /// <param name="oidColumnName">Name of column with unique identifier</param>   
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
		/// <param name="SRID">The spatial reference id</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType, bool useSpatialIndexExtentAsExtent, int SRID)   
		{   
            ConnectionString = connectionStr;   
            Table = tablename;

            if (Table.IndexOf(".") > 0)
            {
                string[] parts = Table.Split('.');
                Table = parts[1];
                TableSchema = parts[0];

            }

            GeometryColumn = geometryColumnName;   
            ObjectIdColumn = oidColumnName;
            _spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
                case SqlServerSpatialObjectType.Geometry:
                    _spatialObject = "geometry";
                    break;
                //case SqlServerSpatialObjectType.Geography:
                default:
                    _spatialObject = "geography";
                    break;
            }

            _extentsMode = (useSpatialIndexExtentAsExtent ? SqlServer2008ExtentsMode.SpatialIndex : SqlServer2008ExtentsMode.QueryIndividualFeatures);
			this.SRID = SRID;
        }
예제 #30
0
 /// <summary>
 /// Returns true if the given geometries relate according to the provided intersection pattern Matrix
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="intersectionPatternMatrix">Intersection pattern Matrix</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static Boolean Relate(Geometry g1, Geometry g2, string intersectionPatternMatrix, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)sg1.STRelate(sg2, intersectionPatternMatrix));
     }
     else
     {
         throw new ArgumentOutOfRangeException("Geography does not support STRelate. You must first convert Geography to Geometry using WKB");
     }
 }
예제 #31
0
 public SqlServer2008(string connectionStr, string tablename, string spatialColumnName, string oidColumnName,
                      SqlServerSpatialObjectType spatialObjectType)
     : this(connectionStr, tablename, spatialColumnName, oidColumnName, spatialObjectType, false)
 {
 }
예제 #32
0
        /// <summary>   
        /// Initializes a new connection to SQL Server   
        /// </summary>   
        /// <param name="connectionStr">Connectionstring</param>   
        /// <param name="tablename">Name of data table</param>   
        /// <param name="geometryColumnName">Name of geometry column</param>   
        /// <param name="oidColumnName">Name of column with unique identifier</param>   
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType, bool useSpatialIndexExtentAsExtent)   
        {   
            ConnectionString = connectionStr;   
            Table = tablename;   
            GeometryColumn = geometryColumnName;   
            ObjectIdColumn = oidColumnName;
            _spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
                case SqlServerSpatialObjectType.Geometry:
                    _spatialObject = "geometry";
                    break;
                //case SqlServerSpatialObjectType.Geography:
                default:
                    _spatialObject = "geography";
                    break;
            }

            _UseSpatialIndexExtentAsExtent = useSpatialIndexExtentAsExtent;
        }
예제 #33
0
 /// <summary>   
 /// Initializes a new connection to SQL Server   
 /// </summary>   
 /// <param name="connectionStr">Connectionstring</param>   
 /// <param name="tablename">Name of data table</param>   
 /// <param name="geometryColumnName">Name of geometry column</param>   
 /// <param name="oidColumnName">Name of column with unique identifier</param>   
 /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
 public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType)
     :this(connectionStr,tablename,geometryColumnName, oidColumnName, spatialObjectType,false)
 {
 }
예제 #34
0
 /// <summary>   
 /// Initializes a new connection to SQL Server   
 /// </summary>   
 /// <param name="connectionStr">Connectionstring</param>   
 /// <param name="tablename">Name of data table</param>   
 /// <param name="geometryColumnName">Name of geometry column</param>   
 /// <param name="oidColumnName">Name of column with unique identifier</param>   
 /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
 /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
 public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType, bool useSpatialIndexExtentAsExtent)   
 :this(connectionStr,tablename,geometryColumnName, oidColumnName, spatialObjectType,false,0)
 {
 }
예제 #35
0
        /// <summary>   
        /// Initializes a new connection to SQL Server   
        /// </summary>   
        /// <param name="connectionStr">Connectionstring</param>   
        /// <param name="tablename">Name of data table</param>   
        /// <param name="geometryColumnName">Name of geometry column</param>   
        /// <param name="oidColumnName">Name of column with unique identifier</param>   
        /// <param name="spatialObjectType">The type of the spatial object to use for spatial queries</param>
        /// <param name="useSpatialIndexExtentAsExtent">If true, the bounds of the spatial index is used for the GetExtents() method which heavily increases performance instead of reading through all features in the table</param>
        public SqlServer2008(string connectionStr, string tablename, string geometryColumnName, string oidColumnName, SqlServerSpatialObjectType spatialObjectType, bool useSpatialIndexExtentAsExtent)   
        {   
            ConnectionString = connectionStr;   
            Table = tablename;   
            GeometryColumn = geometryColumnName;   
            ObjectIdColumn = oidColumnName;
            _spatialObjectType = spatialObjectType;
            switch (spatialObjectType)
            {
                case SqlServerSpatialObjectType.Geometry:
                    _spatialObject = "geometry";
                    break;
                //case SqlServerSpatialObjectType.Geography:
                default:
                    _spatialObject = "geography";
                    break;
            }

            _ExtentsMode = (useSpatialIndexExtentAsExtent ? SqlServer2008ExtentsMode.SpatialIndex : SqlServer2008ExtentsMode.QueryIndividualFeatures);
        }
예제 #36
0
        public void TestGetFeatureInvalidGeometry(SqlServerProviderMode providerMode, SqlServerSpatialObjectType spatialType, bool validateGeometries)
        {
            SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(providerMode, spatialType);
            sq.ValidateGeometries = validateGeometries;

            var feature = sq.GetFeature(_idInvalidGeom);

            Assert.IsNotNull(feature);
            if (providerMode == SqlServerProviderMode.NativeSqlBytes)
            {
                // client side conversion always attempts validation
                Assert.IsTrue(!feature.Geometry.IsEmpty && feature.Geometry.IsValid);
            }
            else
            {
                if (validateGeometries)
                {
                    Assert.IsTrue(!feature.Geometry.IsEmpty && feature.Geometry.IsValid);
                }
                else
                {
                    Assert.IsTrue(feature.Geometry.IsEmpty);
                }
            }
        }