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


C# SharpMap.Close方法代码示例

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


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

示例1: CreateDataTable


//.........这里部分代码省略.........
		{
			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
					SharpMap.Data.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];
					if (feature.Geometry != null)
					{
						command.Parameters["@WKB_Geometry"].Value = feature.Geometry.AsBinary(); //Add the geometry as Well-Known Binary
						SharpMap.Geometries.BoundingBox box = feature.Geometry.GetBoundingBox();
						command.Parameters["@Envelope_MinX"].Value = box.Left;
						command.Parameters["@Envelope_MinY"].Value = box.Bottom;
						command.Parameters["@Envelope_MaxX"].Value = box.Right;
						command.Parameters["@Envelope_MaxY"].Value = box.Top;
					}
					else
					{
						command.Parameters["@WKB_Geometry"].Value = DBNull.Value;
						command.Parameters["@Envelope_MinX"].Value = DBNull.Value;
						command.Parameters["@Envelope_MinY"].Value = DBNull.Value;
						command.Parameters["@Envelope_MaxX"].Value = DBNull.Value;
						command.Parameters["@Envelope_MaxY"].Value = DBNull.Value;
					}
					//Insert row
					command.ExecuteNonQuery();
					counter++;
				}
				//Create indexes
				command.Parameters.Clear();
				command.CommandText = "CREATE INDEX [IDX_Envelope_MinX] ON " + tablename + " (Envelope_MinX)";
				command.ExecuteNonQuery();
				command.CommandText = "CREATE INDEX [IDX_Envelope_MinY] ON " + tablename + " (Envelope_MinY)";
				command.ExecuteNonQuery();
				command.CommandText = "CREATE INDEX [IDX_Envelope_MaxX] ON " + tablename + " (Envelope_MaxX)";
				command.ExecuteNonQuery();
				command.CommandText = "CREATE INDEX [IDX_Envelope_MaxY] ON " + tablename + " (Envelope_MaxY)";
				command.ExecuteNonQuery();

				conn.Close();
			}
			datasource.Close();
			return counter;
		}
开发者ID:lishxi,项目名称:_SharpMap,代码行数:101,代码来源:MsSql.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(SharpMap.Data.Providers.IProvider provider)
        {            
            // Features list initialization
            features = new List<GisSharpBlog.NetTopologySuite.Features.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)
                {
                    SharpMap.Data.FeatureDataRow dataRow = provider.GetFeature(id);
                    GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry = GeometryConverter.ToNTSGeometry(dataRow.Geometry, geometryFactory);
                    GisSharpBlog.NetTopologySuite.Features.AttributesTable attributes = new GisSharpBlog.NetTopologySuite.Features.AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {                        
                        if (dataRow[column] == null || dataRow[column].GetType() == typeof(System.DBNull))
                            throw new ApplicationException("Null values not supported");
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    features.Add(new GisSharpBlog.NetTopologySuite.Features.Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                    provider.Close();
            }
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:37,代码来源:NtsProvider.cs

示例3: CreateDataTable


//.........这里部分代码省略.........
            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
                    SharpMap.Data.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)
                        command.Parameters["@" + col.ColumnName].Value = feature[col];
                    if (feature.Geometry != null)
                    {
                        System.Console.WriteLine(feature.Geometry.AsBinary().Length.ToString());
                        command.Parameters.AddWithValue("@geom", feature.Geometry.AsText()); //.AsBinary());
                        //command.Parameters["@geom"].Value = "X'" + ToHexString(feature.Geometry.AsBinary()) + "'"; //Add the geometry as Well-Known Binary
                        IEnvelope box = feature.Geometry.EnvelopeInternal;
                        command.Parameters["@minx"].Value = box.MinX;
                        command.Parameters["@miny"].Value = box.MinY;
                        command.Parameters["@maxx"].Value = box.MaxX;
                        command.Parameters["@maxy"].Value = box.MaxY;
                    }
                    else
                    {
                        command.Parameters["@geom"].Value = DBNull.Value;
                        command.Parameters["@minx"].Value = DBNull.Value;
                        command.Parameters["@miny"].Value = DBNull.Value;
                        command.Parameters["@maxx"].Value = DBNull.Value;
                        command.Parameters["@maxy"].Value = DBNull.Value;
                    }
                    //Insert row
                    command.ExecuteNonQuery();
                    counter++;
                }
                //Create indexes
                //command.Parameters.Clear();
                //command.CommandText = "CREATE INDEX [IDX_Envelope_MinX] ON " + tablename + " (Envelope_MinX)";
                //command.ExecuteNonQuery();
                //command.CommandText = "CREATE INDEX [IDX_Envelope_MinY] ON " + tablename + " (Envelope_MinY)";
                //command.ExecuteNonQuery();
                //command.CommandText = "CREATE INDEX [IDX_Envelope_MaxX] ON " + tablename + " (Envelope_MaxX)";
                //command.ExecuteNonQuery();
                //command.CommandText = "CREATE INDEX [IDX_Envelope_MaxY] ON " + tablename + " (Envelope_MaxY)";
                //command.ExecuteNonQuery();

                conn.Close();
            }
            datasource.Close();
            return counter;
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:101,代码来源:SqlLite.cs


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