当前位置: 首页>>代码示例>>C#>>正文


C# IProvider.GetExtents方法代码示例

本文整理汇总了C#中IProvider.GetExtents方法的典型用法代码示例。如果您正苦于以下问题:C# IProvider.GetExtents方法的具体用法?C# IProvider.GetExtents怎么用?C# IProvider.GetExtents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProvider的用法示例。


在下文中一共展示了IProvider.GetExtents方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestProvider

        private static void TestProvider(IProvider provider, GpkgContent content)
        {
            int numFeatures = 0;
            Assert.DoesNotThrow(() => numFeatures = provider.GetFeatureCount(),
                    "GetFeatureCount threw exception:\n\tConnection{0}\n\t{1}",
                    provider.ConnectionID, content.TableName);

            var extent = provider.GetExtents();

            Collection<uint> oids = null;
            Assert.DoesNotThrow(() => oids = provider.GetObjectIDsInView(extent), 
                    "GetObjectIDsInView threw exception:\n\tConnection{0}\n\t{1}", 
                    provider.ConnectionID, content.TableName);
            Assert.AreEqual(numFeatures, oids.Count);

            foreach (var oid in oids)
            {
                IGeometry geom = null;
                Assert.DoesNotThrow(() => geom = provider.GetGeometryByID(oid), 
                    "GetGeometryByID threw exception:\n\tConnection{0}\n\t{1}", 
                    provider.ConnectionID, content.TableName);
                FeatureDataRow feat = null;
                Assert.DoesNotThrow(() => feat = provider.GetFeature(oid), 
                    "GetFeature threw exception:\n\tConnection{0}\n\t{1}", 
                    provider.ConnectionID, content.TableName);
                
                Assert.IsTrue(geom.EqualsExact(feat.Geometry));

            }

            Collection<IGeometry> geoms = null;
            Assert.DoesNotThrow(() => geoms = provider.GetGeometriesInView(extent),
                    "GetFeature threw exception:\n\tConnection{0}\n\t{1}",
                    provider.ConnectionID, content.TableName);

            Assert.AreEqual(numFeatures, geoms.Count);
            
            var fds = new FeatureDataSet();
            Assert.DoesNotThrow(() => provider.ExecuteIntersectionQuery(extent, fds),
                    "GetFeature threw exception:\n\tConnection{0}\n\t{1}",
                    provider.ConnectionID, content.TableName);
            Assert.AreEqual(numFeatures, fds.Tables[0].Rows.Count);


        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:45,代码来源:GeoPackageTest.cs

示例2: BuildFromProvider

        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/> 
        /// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(IProvider provider)
        {
            // Features list initialization
            features = new List<Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();
                Collection<uint> ids = provider.GetObjectIDsInView(provider.GetExtents());
                foreach (uint id in ids)
                {
                    FeatureDataRow dataRow = provider.GetFeature(id);
                    GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry =
                        GeometryConverter.ToNTSGeometry(dataRow.Geometry, geometryFactory);
                    AttributesTable attributes = new AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {
                        if (dataRow[column] == null || dataRow[column].GetType() == typeof (DBNull))
                            throw new ApplicationException("Null values not supported");
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    features.Add(new Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                    provider.Close();
            }
        }
开发者ID:goranpavlovic,项目名称:Gis,代码行数:38,代码来源:NtsProvider.cs

示例3: BuildFromProvider

        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/> 
        /// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(IProvider provider)
        {
            // Features list initialization
            _features = new List<Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();
                var ids = provider.GetOidsInView(provider.GetExtents());
                foreach (var id in ids)
                {
                    var dataRow = provider.GetFeatureByOid(id);
                    var geometry = dataRow.Geometry;
                    AttributesTable attributes = new AttributesTable();
                    var att = dataRow.Attributes;
                    foreach (var column in dataRow.Factory.AttributesDefinition)
                    {
                        var attName = column.AttributeName;
                        if (att[attName] == null || att[attName] is DBNull)
                            throw new ApplicationException("Null values not supported");
                        attributes.AddAttribute(attName, att[column.AttributeName]);
                    }
                    _features.Add(new Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                    provider.Close();
            }
        }
开发者ID:geobabbler,项目名称:SharpMap,代码行数:39,代码来源:NtsProvider.cs

示例4: CreateDataTable

        /// <summary>
        /// Creates a new table in a Microsoft SQL Server database and copies rows from an existing datasource.
        /// </summary>
        /// <remarks>
        /// <para>The datatable created will contain six extra columns besides the attribute data: "OID" (Object ID row), 
        /// "WKB_Geometry" (Geometry stored as WKB), and Envelope_MinX, Envelope_MinY, Envelope_MaxX, Envelope_MaxY
        /// for geometry bounding box.</para>
        /// <para>
        /// <example>
        /// Upload a ShapeFile to a database:
        /// <code>
        /// public void CreateDatabase(string shapeFile)
        /// {
        ///		if (!System.IO.File.Exists(shapeFile))
        ///		{
        ///			MessageBox.Show("File not found");
        ///			return;
        ///		}
        ///		ShapeFile shp = new ShapeFile(shapeFile, false);
        ///		//Create tablename from filename
        ///		string tablename = shapeFile.Substring(shapeFile.LastIndexOf('\\') + 1,
        ///			shapeFile.LastIndexOf('.') - shapeFile.LastIndexOf('\\') - 1);
        ///		//Create connectionstring
        ///		string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|GeoDatabase.mdf;Integrated Security=True;User Instance=True";
        ///		int count = SharpMap.Data.Providers.MsSql.CreateDataTable(shp, tablename, connstr);
        ///		MessageBox.Show("Uploaded " + count.ToString() + " features to datatable '" + tablename + "'");
        ///	}
        /// </code>
        /// </example>
        /// </para>
        /// </remarks>
        /// <param name="datasource">Datasource to upload</param>
        /// <param name="tablename">Name of table to create (existing table will be overwritten!)</param>
        /// <param name="connstr">Connection string to database</param>
        /// <returns>Number or rows inserted, -1 if failed and 0 if table created but no rows inserted.</returns>        
        public static int CreateDataTable(IProvider datasource, string tablename, string connstr)
        {
            datasource.Open();
            FeatureDataRow geom = datasource.GetFeature(0);
            DataColumnCollection columns = geom.Table.Columns;
            int counter = -1;
            using (SQLiteConnection conn = new SQLiteConnection(connstr))
            {
                SQLiteCommand command = new SQLiteCommand();
                command.Connection = conn;

                conn.Open();
                //Try to drop table if it exists
                try
                {
                    command.CommandText = "DROP TABLE \"" + tablename + "\";";
                    command.ExecuteNonQuery();
                }
                catch
                {
                }
                //Create new table for storing the datasource
                string sql = "CREATE TABLE " + tablename + " (fid INTEGER PRIMARY KEY, geom TEXT, " +
                             "minx REAL, miny REAL, maxx REAL, maxy REAL, oid INTEGER";
                foreach (DataColumn col in columns)
                    if (col.DataType != typeof (String))
                        sql += ", " + col.ColumnName + " " + Type2SqlLiteTypeString(col.DataType);
                    else
                        sql += ", " + col.ColumnName + " TEXT";
                command.CommandText = sql + ");";
                //command.CommandText = sql;
                command.ExecuteNonQuery();
                counter++;
                Collection<uint> indexes = datasource.GetObjectIDsInView(datasource.GetExtents());
                //Select all indexes in shapefile, loop through each feature and insert them one-by-one
                foreach (uint idx in indexes)
                {
                    //Get feature from shapefile
                    FeatureDataRow feature = datasource.GetFeature(idx);
                    if (counter == 0)
                    {
                        //Create insert script
                        string strSQL = " (";
                        foreach (DataColumn col in feature.Table.Columns)
                            strSQL += "@" + col.ColumnName + ",";

                        strSQL += "@geom,@minx,@miny, " +
                                  "@maxx,@maxy)";
                        strSQL = "INSERT INTO " + tablename + strSQL.Replace("@", "") + " VALUES" + strSQL;

                        command.CommandText = strSQL;
                        command.Parameters.Clear();
                        //Add datacolumn parameters
                        foreach (DataColumn col in feature.Table.Columns)
                            command.Parameters.Add("@" + col.ColumnName, Type2SqlType(col.DataType));

                        //Add geometry parameters
                        //command.Parameters.Add("@geom", DbType.Binary);
                        command.Parameters.Add("@minx", DbType.Double);
                        command.Parameters.Add("@miny", DbType.Double);
                        command.Parameters.Add("@maxx", DbType.Double);
                        command.Parameters.Add("@maxy", DbType.Double);
                    }
                    //Set values
                    foreach (DataColumn col in feature.Table.Columns)
//.........这里部分代码省略.........
开发者ID:lishxi,项目名称:_SharpMap,代码行数:101,代码来源:SqlLite.cs

示例5: CreateDataTable

        /// <summary>
        /// Creates a new table in a Microsoft SQL Server database and copies rows from an existing datasource.
        /// </summary>
        /// <remarks>
        /// <para>The datatable created will contain six extra columns besides the attribute data: "OID" (Object ID row), 
        /// "WKB_Geometry" (Geometry stored as WKB), and Envelope_MinX, Envelope_MinY, Envelope_MaxX, Envelope_MaxY
        /// for geometry bounding box.</para>
        /// <para>
        /// <example>
        /// Upload a ShapeFile to a database:
        /// <code>
        /// public void CreateDatabase(string shapeFile)
        /// {
        ///		if (!System.IO.File.Exists(shapeFile))
        ///		{
        ///			MessageBox.Show("File not found");
        ///			return;
        ///		}
        ///		ShapeFile shp = new ShapeFile(shapeFile, false);
        ///		//Create tablename from filename
        ///		string tablename = shapeFile.Substring(shapeFile.LastIndexOf('\\') + 1,
        ///			shapeFile.LastIndexOf('.') - shapeFile.LastIndexOf('\\') - 1);
        ///		//Create connectionstring
        ///		string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|GeoDatabase.mdf;Integrated Security=True;User Instance=True";
        ///		int count = SharpMap.Data.Providers.MsSql.CreateDataTable(shp, tablename, connstr);
        ///		MessageBox.Show("Uploaded " + count.ToString() + " features to datatable '" + tablename + "'");
        ///	}
        /// </code>
        /// </example>
        /// </para>
        /// </remarks>
        /// <param name="datasource">Datasource to upload</param>
        /// <param name="tablename">Name of table to create (existing table will be overwritten!)</param>
        /// <param name="connstr">Connection string to database</param>
        /// <returns>Number or rows inserted, -1 if failed and 0 if table created but no rows inserted.</returns>
        public static int CreateDataTable(IProvider datasource, string tablename, string connstr)
        {
            datasource.Open();
            FeatureDataRow geom = datasource.GetFeature(0);
            DataColumnCollection columns = geom.Table.Columns;
            int counter = -1;
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                SqlCommand command = new SqlCommand();
                command.Connection = conn;

                conn.Open();
                //Try to drop table if it exists
                try
                {
                    command.CommandText = "DROP TABLE \"" + tablename + "\";";
                    command.ExecuteNonQuery();
                }
                catch
                {
                }
                //Create new table for storing the datasource
                string sql = "CREATE TABLE " + tablename + " (oid INTEGER IDENTITY PRIMARY KEY, WKB_Geometry Image, " +
                             "Envelope_MinX real, Envelope_MinY real, Envelope_MaxX real, Envelope_MaxY real";
                foreach (DataColumn col in columns)
                    if (col.DataType != typeof (String))
                        sql += ", " + col.ColumnName + " " + Type2SqlType(col.DataType).ToString();
                    else
                        sql += ", " + col.ColumnName + " VARCHAR(256)";
                command.CommandText = sql + ");";
                command.ExecuteNonQuery();
                counter++;
                Collection<uint> indexes = datasource.GetObjectIDsInView(datasource.GetExtents());
                //Select all indexes in shapefile, loop through each feature and insert them one-by-one
                foreach (uint idx in indexes)
                {
                    //Get feature from shapefile
                    FeatureDataRow feature = datasource.GetFeature(idx);
                    if (counter == 0)
                    {
                        //Create insert script
                        string strSQL = " (";
                        foreach (DataColumn col in feature.Table.Columns)
                            strSQL += "@" + col.ColumnName + ",";

                        strSQL += "@WKB_Geometry,@Envelope_MinX,@Envelope_MinY, " +
                                  "@Envelope_MaxX,@Envelope_MaxY)";
                        strSQL = "INSERT INTO " + tablename + strSQL.Replace("@", "") + " VALUES" + strSQL;

                        command.CommandText = strSQL;
                        command.Parameters.Clear();
                        //Add datacolumn parameters
                        foreach (DataColumn col in feature.Table.Columns)
                            command.Parameters.Add("@" + col.ColumnName, Type2SqlType(col.DataType));

                        //Add geometry parameters
                        command.Parameters.Add("@WKB_Geometry", SqlDbType.VarBinary);
                        command.Parameters.Add("@Envelope_MinX", SqlDbType.Real);
                        command.Parameters.Add("@Envelope_MinY", SqlDbType.Real);
                        command.Parameters.Add("@Envelope_MaxX", SqlDbType.Real);
                        command.Parameters.Add("@Envelope_MaxY", SqlDbType.Real);
                    }
                    //Set values
                    foreach (DataColumn col in feature.Table.Columns)
                        command.Parameters["@" + col.ColumnName].Value = feature[col];
//.........这里部分代码省略.........
开发者ID:lishxi,项目名称:_SharpMap,代码行数:101,代码来源:MsSql.cs

示例6: BuildFromProvider

        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/> 
        /// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(IProvider provider)
        {
            // Features list initialization
            _features = new List<Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();
                Collection<uint> ids = provider.GetObjectIDsInView(provider.GetExtents());
                foreach (uint id in ids)
                {
                    var dataRow = provider.GetFeature(id);
                    var geometry = dataRow.Geometry;
                    AttributesTable attributes = new AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {
                        if (dataRow[column] == null || dataRow[column] is DBNull)
                            throw new ApplicationException("Null values not supported");
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    _features.Add(new Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                    provider.Close();
            }
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:37,代码来源:NtsProvider.cs

示例7: ThreadingTest

 protected ThreadingTest(IProvider provider)
 {
     _provider = provider;
     _provider.Open();
     _extents = provider.GetExtents();
     _provider.Close();
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:7,代码来源:ThreadingTest.cs

示例8: CreateDataTable

        /// <summary>
        /// Creates a new table in a SQLite database and copies rows from an existing datasource.
        /// </summary>
        /// <remarks>
        /// <para>The datatable created will contain six extra columns besides the attribute data: "oid" (Object ID row), 
        /// "geom" (Geometry stored as WKT), and minx, miny, maxx, maxy for geometry bounding box.</para>
        /// <para>
        /// <example>
        /// Upload a ShapeFile to a database:
        /// <code>
        /// public void CreateDatabase(string shapeFile)
        /// {
        ///		if (!System.IO.File.Exists(shapeFile))
        ///		{
        ///			MessageBox.Show("File not found");
        ///			return;
        ///		}
        ///		ShapeFile shp = new ShapeFile(shapeFile, false);
        ///		//Create tablename from filename
        ///		string tablename = shapeFile.Substring(shapeFile.LastIndexOf('\\') + 1,
        ///			shapeFile.LastIndexOf('.') - shapeFile.LastIndexOf('\\') - 1);
        ///		//Create connectionstring
        ///		string connstr = @"Data Source=|DataDirectory|GeoDatabase.sqlite;Version=3";
        ///		int count = SharpMap.Data.Providers.SqlLite.CreateDataTable(shp, tablename, connstr);
        ///		MessageBox.Show("Uploaded " + count.ToString() + " features to datatable '" + tablename + "'");
        ///	}
        /// </code>
        /// </example>
        /// </para>
        /// </remarks>
        /// <param name="datasource">Datasource to upload</param>
        /// <param name="tablename">Name of table to create (existing table will be overwritten!)</param>
        /// <param name="connstr">Connection string to database</param>
        /// <returns>Number or rows inserted, -1 if failed and 0 if table created but no rows inserted.</returns>        
        public static int CreateDataTable(IProvider datasource, string tablename, string connstr)
        {
            datasource.Open();
            var geom = datasource.GetFeatureByOid(0);
            var columns = geom.Factory.AttributesDefinition;
            int counter = -1;
            using (var conn = new SQLiteConnection(connstr))
            {
                var command = new SQLiteCommand();
                command.Connection = conn;

                conn.Open();
                //Try to drop table if it exists
                try
                {
                    command.CommandText = "DROP TABLE \"" + tablename + "\";";
                    command.ExecuteNonQuery();
                }
                catch
                {
                }
                //Create new table for storing the datasource
                string sql = "CREATE TABLE " + tablename + " (fid INTEGER PRIMARY KEY, geom TEXT, " +
                             "minx REAL, miny REAL, maxx REAL, maxy REAL, oid INTEGER";
                foreach (var col in columns)
                    if (col.AttributeType != typeof (String))
                        sql += ", " + col.AttributeName + " " + Type2SqlLiteTypeString(col.AttributeType);
                    else
                        sql += ", " + col.AttributeName + " TEXT";
                command.CommandText = sql + ");";
                //command.CommandText = sql;
                command.ExecuteNonQuery();
                counter++;
                var indexes = datasource.GetOidsInView(datasource.GetExtents());
                //Select all indexes in shapefile, loop through each feature and insert them one-by-one
                foreach (var idx in indexes)
                {
                    //Get feature from provider
                    var feature = datasource.GetFeatureByOid(idx);
                    if (counter == 0)
                    {
                        //Create insert script
                        var strSQL = " (";
                        foreach (var col in columns)
                            strSQL += "@" + col.AttributeName + ",";

                        strSQL += "@geom,@minx,@miny, " +
                                  "@maxx,@maxy)";
                        strSQL = "INSERT INTO " + tablename + strSQL.Replace("@", "") + " VALUES" + strSQL;

                        command.CommandText = strSQL;
                        command.Parameters.Clear();
                        //Add datacolumn parameters
                        foreach (var col in columns)
                            command.Parameters.Add("@" + col.AttributeName, Type2SqlType(col.AttributeType));

                        //Add geometry parameters
                        //command.Parameters.Add("@geom", DbType.Binary);
                        command.Parameters.Add("@minx", DbType.Double);
                        command.Parameters.Add("@miny", DbType.Double);
                        command.Parameters.Add("@maxx", DbType.Double);
                        command.Parameters.Add("@maxy", DbType.Double);
                    }
                    //Set values
                    foreach (var col in columns)
                        command.Parameters["@" + col.AttributeName].Value = feature.Attributes[col.AttributeName];
//.........这里部分代码省略.........
开发者ID:geobabbler,项目名称:SharpMap,代码行数:101,代码来源:SqlLite.cs


注:本文中的IProvider.GetExtents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。