本文整理汇总了C#中IProvider.GetOidsInView方法的典型用法代码示例。如果您正苦于以下问题:C# IProvider.GetOidsInView方法的具体用法?C# IProvider.GetOidsInView怎么用?C# IProvider.GetOidsInView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProvider
的用法示例。
在下文中一共展示了IProvider.GetOidsInView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: 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];
//.........这里部分代码省略.........