コード例 #1
0
ファイル: SpatialOperationsEx.cs プロジェクト: cugkgq/Project
        public static Geometry ConvexHull(Geometry g)
        {
            SqlGeometry sg           = SqlGeometryConverter.ToSqlGeometry(g);
            SqlGeometry sgConvexHull = sg.STConvexHull();

            return(SqlGeometryConverter.ToSharpMapGeometry(sgConvexHull));
        }
コード例 #2
0
ファイル: SpatialOperationsEx.cs プロジェクト: cugkgq/Project
        public static Geometry Buffer(Geometry g, Double distance)
        {
            SqlGeometry sg       = SqlGeometryConverter.ToSqlGeometry(g);
            SqlGeometry sgBuffer = sg.STBuffer(distance);

            return(SqlGeometryConverter.ToSharpMapGeometry(sgBuffer));
        }
コード例 #3
0
        /// <summary>
        /// Returns the geometry corresponding to the Object ID
        /// </summary>
        /// <param name="oid">Object ID</param>
        /// <returns>geometry</returns>
        public override Geometry GetGeometryByID(uint oid)
        {
            Geometry geom = null;

            using (var conn = new SqlConnection(ConnectionString))
            {
                string strSql = "SELECT g." + GeometryColumn + " FROM " + QualifiedTable + " g WHERE " + ObjectIdColumn + "='" + oid + "'";
                conn.Open();
                using (var command = new SqlCommand(strSql, conn))
                {
                    using (SqlDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != null && dr[0] != DBNull.Value)
                            {
                                geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]);
                            }
                        }
                    }
                }
                conn.Close();
            }
            return(geom);
        }
コード例 #4
0
ファイル: SpatialOperationsEx.cs プロジェクト: cugkgq/Project
        public static Geometry Boundary(Geometry g)
        {
            SqlGeometry sg         = SqlGeometryConverter.ToSqlGeometry(g);
            SqlGeometry sgBoundary = sg.STBoundary();

            return(SqlGeometryConverter.ToSharpMapGeometry(sgBoundary));
        }
コード例 #5
0
        /// <summary>
        /// Returns all features with the view box
        /// </summary>
        /// <param name="bbox">view box</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                string strSql = String.Format(
                    "SELECT g.* FROM {0} g {1} WHERE ",
                    Table, BuildTableHints());

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strBbox;

                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    var ds2 = new System.Data.DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds2.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();

                            foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      geom        = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (geom != null && geom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom);
                            }
                            fdr.Geometry = sqlGeometry;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
コード例 #6
0
ファイル: SqlServer2008.cs プロジェクト: cugkgq/Project
        private Geometry ToSqlServerAndBack(Geometry gIn)
        {
            SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn);
            Geometry    gOut        = SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry);

            return(gOut);
        }
コード例 #7
0
ファイル: SpatialOperationsEx.cs プロジェクト: cugkgq/Project
        public static Geometry SymDifference(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1             = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2             = SqlGeometryConverter.ToSqlGeometry(g2);
            SqlGeometry sgSymDifference = sg1.STSymDifference(sg2);

            return(SqlGeometryConverter.ToSharpMapGeometry(sgSymDifference));
        }
コード例 #8
0
ファイル: SpatialOperationsEx.cs プロジェクト: cugkgq/Project
        public static Geometry Intersection(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1            = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2            = SqlGeometryConverter.ToSqlGeometry(g2);
            SqlGeometry sgIntersection = sg1.STIntersection(sg2);

            return(SqlGeometryConverter.ToSharpMapGeometry(sgIntersection));
        }
コード例 #9
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string strGeom = SpatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(CultureInfo.InvariantCulture) : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSql = "SELECT g.* FROM " + Table + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strGeom;

                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      ogeom       = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (ogeom != null && ogeom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)ogeom);
                            }
                            fdr.Geometry = sqlGeometry;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
コード例 #10
0
        private Geometry ToSqlServerAndBack(Geometry gIn)
        {
            Assert.That(gIn, Is.Not.Null);
            Assert.That(gIn.SRID, Is.EqualTo(-1));
            gIn.SRID = 0;
            SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn);
            Geometry    gOut        = SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry, new NetTopologySuite.Geometries.GeometryFactory());

            return(gOut);
        }
コード例 #11
0
ファイル: SpatialOperationsEx.cs プロジェクト: cugkgq/Project
        public static Geometry Union(Geometry g, params Geometry[] geometries)
        {
            SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g);

            foreach (SqlGeometry sgUnion in SqlGeometryConverter.ToSqlGeometries(geometries))
            {
                sg = sg.STUnion(sgUnion);
            }
            return(SqlGeometryConverter.ToSharpMapGeometry(sg));
        }
コード例 #12
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox)
        {
            var features = new Collection <Geometry>();

            using (var conn = new SqlConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                string strSql = "SELECT g." + GeometryColumn + GetMakeValidString();
                strSql += " FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                if (!ValidateGeometries ||
                    (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex))))
                {
                    // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr
                    strSql += $"{GeometryColumn}.STIsValid() = 1 AND ";
                }

                strSql += strBbox;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSql += " " + extraOptions;
                }

                using (var command = new SqlCommand(strSql, conn))
                {
                    conn.Open();
                    using (SqlDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != null && dr[0] != DBNull.Value)
                            {
                                Geometry geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]);
                                if (geom != null)
                                {
                                    features.Add(geom);
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(features);
        }
コード例 #13
0
        /// <summary>
        /// Computes the boundary 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 boundary</returns>
        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));
            }

            throw new ArgumentOutOfRangeException("Geography does not support STBoundary");
        }
コード例 #14
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));
     }
 }
コード例 #15
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));
     }
 }
コード例 #16
0
        /// <summary>
        /// Returns a datarow based on a RowID
        /// </summary>
        /// <param name="rowId"></param>
        /// <returns>datarow</returns>
        public override FeatureDataRow GetFeature(uint rowId)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string strSql = "select g.* from " + QualifiedTable + " g WHERE " + ObjectIdColumn + "=" + rowId + "";
                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    var ds = new System.Data.DataSet();
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            System.Data.DataRow dr  = ds.Tables[0].Rows[0];
                            FeatureDataRow      fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      geom        = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (geom != null && geom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom);
                            }
                            fdr.Geometry = sqlGeometry;
                            return(fdr);
                        }
                        return(null);
                    }
                    return(null);
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox)
        {
            var features = new Collection <Geometry>();

            using (var conn = new SqlConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                string strSql = "SELECT g." + GeometryColumn;
                strSql += " FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strBbox;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSql += " " + extraOptions;
                }

                using (var command = new SqlCommand(strSql, conn))
                {
                    conn.Open();
                    using (SqlDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != null && dr[0] != DBNull.Value)
                            {
                                Geometry geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]);
                                if (geom != null)
                                {
                                    features.Add(geom);
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(features);
        }
コード例 #18
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));
     }
 }
コード例 #19
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));
     }
 }
コード例 #20
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));
     }
 }
コード例 #21
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()));
            }
        }
コード例 #22
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string strGeom = SpatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(CultureInfo.InvariantCulture) : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSql = "SELECT g.* FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                if (!ValidateGeometries ||
                    (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex))))
                {
                    // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr
                    strSql += $"{GeometryColumn}.STIsValid() = 1 AND ";
                }

                strSql += strGeom;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSql += " " + extraOptions;
                }

                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      ogeom       = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (ogeom != null && ogeom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)ogeom);
                            }
                            fdr.Geometry = sqlGeometry;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
コード例 #23
0
        /// <summary>
        /// Returns all features with the view box
        /// </summary>
        /// <param name="bbox">view box</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                string strSql = String.Format(
                    "SELECT g.* FROM {0} g {1} WHERE ",
                    QualifiedTable, BuildTableHints());

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                if (!ValidateGeometries ||
                    (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex))))
                {
                    // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr
                    strSql += $"{GeometryColumn}.STIsValid() = 1 AND ";
                }

                strSql += strBbox;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSql += " " + extraOptions;
                }

                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    var ds2 = new System.Data.DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds2.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();

                            foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      geom        = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (geom != null && geom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom);
                            }
                            fdr.Geometry = sqlGeometry;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }