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");
     }
 }
 /// <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));
     }
 }
        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);
        }
 /// <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");
     }
 }
 /// <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));
     }
 }
        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);
        }
 /// <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));
     }
 }
 /// <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));
     }
 }
 /// <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)));
     }
 }
        //[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);
        }
 /// <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));
     }
 }
 /// <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));
     }
 }
Example #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);
            }
        }
Example #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);
        }
        /// <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;
        }
Example #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);
        }
 /// <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));
     }
 }
Example #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;
        }
Example #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()));
            }
        }
Example #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());
        }
Example #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]));
                    }
                }
            }
        }
Example #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);
        }
Example #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;
        }
        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
                });
            }
        }
Example #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);
        }
Example #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)
 {
 }
Example #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)
 {
 }
Example #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;
        }
Example #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");
     }
 }
Example #31
0
 public SqlServer2008(string connectionStr, string tablename, string spatialColumnName, string oidColumnName,
                      SqlServerSpatialObjectType spatialObjectType)
     : this(connectionStr, tablename, spatialColumnName, oidColumnName, spatialObjectType, false)
 {
 }
Example #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;
        }
Example #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)
 {
 }
Example #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)
 {
 }
Example #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);
        }
Example #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);
                }
            }
        }