⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miapi.cs

📁 mitab,读取MapInfo的地图文件
💻 CS
📖 第 1 页 / 共 2 页
字号:
// $Id: MiApi.cs,v 1.2 2005/03/24 17:02:06 dmorissette Exp $
//

using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections;

namespace EBop.MapObjects.MapInfo {

	// feature type values
	public enum FeatureType {
		TABFC_NoGeom = 0,
		TABFC_Point = 1,
		TABFC_FontPoint = 2,
		TABFC_CustomPoint = 3,
		TABFC_Text = 4,
		TABFC_Polyline = 5,
		TABFC_Arc = 6,
		TABFC_Region = 7,
		TABFC_Rectangle = 8,
		TABFC_Ellipse = 9,
		TABFC_MultiPoint = 10};

	public enum FieldType { 
		TABFT_Char = 1,
		TABFT_Integer = 2,
		TABFT_SmallInt = 3,
		TABFT_Decimal = 4,
		TABFT_Float = 5,
		TABFT_Date = 6,
		TABFT_Logical = 7};

	public enum Justification {
		TABTJ_Left = 0,
		TABTJ_Center = 1,
		TABTJ_Right = 2};

	public enum TextSpacing {
		TABTS_Single = 0,
		TABTS_1_5 = 1,
		TABTS_Double = 2};

	// test linetype
	public enum LineSpacing {
		TABTL_NoLine = 0,
		TABTL_Simple = 1,
		TABTL_Arrow = 2};

	/// <summary>
	/// Wrapper functions for the version 1.3.0 of the MapInfo Tab API.
	/// </summary>
	/// <remarks>
	/// Requires mitab.dll (www.maptools.org)
	/// See http://mitab.maptools.org/
	/// 
	/// Graham Sims
	/// Environment Bay of Plenty, Whakatane, New Zealand
	/// http://www.envbop.govt.nz
	/// </remarks>
	public class MiApi {

		private MiApi() {
		}
		
		/// <summary>
		/// Returns the version of the library. 
		/// </summary>
		/// <returns>An integer representing the current version of the MITAB library in the 
		/// format xxxyyyzzz, e.g. returns 1002004 for v1.2.4.  
		/// </returns>
		[DllImport("mitab.dll")]
		public static extern int mitab_c_getlibversion();

		/// <summary>
		/// Get the last error message. 
		/// </summary>
		/// <remarks>
		/// Fetches the last error message posted with CPLError(), that hasn't been cleared by CPLErrorReset(). 
		/// The returned pointer is to an internal string that should not be altered or freed. 
		/// </remarks>
		/// <returns>A pointer to the last error message, or an empty string if there is no posted error message</returns>
		[DllImport("mitab.dll", EntryPoint="mitab_c_getlasterrormsg")]
		private static extern IntPtr _mitab_c_getlasterrormsg();
		public static string mitab_c_getlasterrormsg() {
			return Marshal.PtrToStringAnsi(_mitab_c_getlasterrormsg());
		}
		
//		[DllImport("mitab.dll")]
//		public static extern int mitab_c_getlasterrormsg_vb (
//			[MarshalAs(UnmanagedType.LPStr, SizeConst = 260)] string errormsg, int l);

		/// <summary>
		/// Fetch the last error number. 
		/// </summary>
		/// <remarks>This is the error number, not the error class. </remarks>
		/// <returns>The error number of the last error to occur, or CPLE_None (0) if there are no posted errors</returns>
		[DllImport("mitab.dll")]
		public static extern int mitab_c_getlasterrorno();

		/// <summary>
		/// Open an existing .TAB or .MIF dataset for read access. 
		/// </summary>
		/// <remarks>The function automatically detects the format (.MIF or .TAB) of the specified file.
		/// Note that it is not possible to open a file for update (i.e. read+write) with the current 
		/// version of the library.</remarks>
		/// <param name="filename">The complete filename (including extension .TAB or .MIF) of the file to open.</param>
		/// <returns>A valid mitab_handle, or NULL if the file could not be opened.</returns>
		[DllImport("mitab.dll")]
		public static extern IntPtr mitab_c_open([MarshalAs(UnmanagedType.LPStr)] string filename);

		/// <summary>
		/// Close a dataset previously opened using mitab_c_open() or created using mitab_c_create(). 
		/// </summary>
		/// <param name="mitab_handle">The mitab_handle of the dataset to close.</param>
		[DllImport("mitab.dll")]
		public static extern void mitab_c_close(IntPtr mitab_handle);

		/// <summary>
		/// Create a new .TAB or .MIF dataset.
		/// </summary>
		/// <remarks>
		/// Note that it is not possible to open a file for update (i.e. read+write) with the current version 
		/// of the library.
		/// </remarks>
		/// <param name="filename">The complete filename (including extension .TAB or .MIF) of the file to create.</param>
		/// <param name="mif_or_tab">One of "mif" to create a .MIF dataset or "tab" to create a .TAB dataset. 
		/// The default is to create a TAB dataset if this parameter's value is NULL or an empty string.</param>
		/// <param name="mif_projectiondef">The projection to use for the dataset, in the same format that is 
		/// used in the "CoordSys" line of a MIF file header. If this parameter's value is NULL or empty then 
		/// a LAT/LON coordsys is assumed. See also mitab_c_get_mif_coordsys().</param>
		/// <param name="north">The upper dataset bound. Note that valid bounds are required for a .TAB dataset 
		/// otherwise data may not be stored properly in the file. MITAB knows the default bounds only for the 
		/// most common MapInfo coordinate systems, passing north,south,east,west as 0,0,0,0 will instruct MITAB
		///  to attempt to use the default bounds for that projection. If no default bounds are found for this 
		///  projection then your data may not be stored properly in the file unless you provide valid bounds 
		///  via the north,south,east,west parameters.</param>
		/// <param name="south">The lower dataset bound.</param>
		/// <param name="east">The right dataset bound. </param>
		/// <param name="west">The left dataset bound.</param>
		/// <returns>A valid mitab_handle, or NULL if the file could not be created.</returns>
		[DllImport("mitab.dll")]
		public static extern IntPtr mitab_c_create( 
			[MarshalAs(UnmanagedType.LPStr)] string filename,
			[MarshalAs(UnmanagedType.LPStr)] string mif_or_tab,
			[MarshalAs(UnmanagedType.LPStr)] string mif_projectiondef,
			double north, double south,
			double east, double west );
												   
		[DllImport("mitab.dll")]
		public static extern IntPtr mitab_c_add_field( IntPtr handle, 
			[MarshalAs(UnmanagedType.LPStr)] string field_name,
			int field_type, int width, int precision, 
			int indexed, int unique );

		[DllImport("mitab.dll")]
		public static extern IntPtr mitab_c_write_feature(IntPtr handle, IntPtr feature );


		/// <summary>
		/// Iterator to get the next valid feature id when reading a dataset opened with mitab_c_open(). 
		/// </summary>
		/// <param name="handle">the mitab_handle of the file opened for read access.</param>
		/// <param name="last_feature_id">The id of the last feature that was read. 
		/// Use -1 to get first feature id in the dataset.</param>
		/// <returns>The next valid feature id in the dataset, or -1 when there are no more feature ids.</returns> 
		[DllImport("mitab.dll")]
		public static extern int mitab_c_next_feature_id(IntPtr handle, int last_feature_id );

		/// <summary>
		/// Read a mitab_feature object from the file. 
		/// </summary>
		/// <remarks>Works only with datasets opened with mitab_c_open().</remarks>
		/// <param name="handle">The mitab_handle of the file opened for read access.</param>
		/// <param name="feature_id">The id of the feature to read, obtained by calling mitab_c_next_feature_id()</param>
		/// <returns>The mitab_feature object that was read. 
		/// The object will have to be destroyed using mitab_c_destroy_feature() once you are done with it.</returns>
		[DllImport("mitab.dll")]
		public static extern IntPtr mitab_c_read_feature( IntPtr handle, int feature_id );

		/// <summary>
		/// Destroy a mitab_feature object and release all memory associated with it. 
		/// </summary>
		/// <param name="feature">The mitab_feature to destroy.</param>
		[DllImport("mitab.dll")]
		public static extern void mitab_c_destroy_feature( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_feature_id( IntPtr feature );

		/// <summary>
		/// Create a new mitab_feature object to be written to a dataset created using mitab_c_create(). 
		/// </summary>
		/// <param name="handle">The handle of the dataset opened for write access.</param>
		/// <param name="feature_type">A member of the feature type enumeration. At this point, only the following 
		/// types can be created by this C API function: TABFC_NoGeom (0), TABFC_Point (1), TABFC_FontPoint (2), 
		/// TABFC_CustomPoint (3), TABFC_Text (4), TABFC_Polyline (5), TABFC_Arc (6), TABFC_Region (7), 
		/// TABFC_Rectangle (8), TABFC_Ellipse (9) and TABFC_MultiPoint (10)</param>
		/// <returns>The new mitab_feature object, or NULL if creation failed. Note that the new object will 
		/// have to be released using mitab_c_destroy_feature().</returns>
		[DllImport("mitab.dll")]
		public static extern IntPtr mitab_c_create_feature( IntPtr handle, int feature_type );

		[DllImport("mitab.dll")]
		public static extern void mitab_c_set_field( IntPtr feature, int field_index, 
			[MarshalAs(UnmanagedType.LPStr)] string value );
    
		[DllImport("mitab.dll")]
		public static extern void mitab_c_set_text( IntPtr feature, 
			[MarshalAs(UnmanagedType.LPStr)] string text );


		/// <summary>
		/// Get the text string on a TABFC_Text object. 
		/// </summary>
		/// <param name="feature">The mitab_feature object.</param>
		/// <returns>A pointer to the text string in the object.</returns>
		[DllImport("mitab.dll", EntryPoint="mitab_c_get_text")]
		public static extern IntPtr _mitab_c_get_text( IntPtr feature );
		public static string mitab_c_get_text( IntPtr feature ) {
			return Marshal.PtrToStringAnsi(_mitab_c_get_text(feature));
		}

//		[DllImport("mitab.dll")]
//		public static extern int mitab_c_get_text_vb( IntPtr  feature, 
//			[MarshalAs(UnmanagedType.LPStr)] string text, int l );

		[DllImport("mitab.dll")]
		public static extern void mitab_c_set_text_display( IntPtr feature,
			double angle, double height, double width,
			int fg_color, int bg_color,
			int justification, int spacing, int linetype );

		[DllImport("mitab.dll")]
		public static extern double mitab_c_get_text_angle( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern double mitab_c_get_text_height( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern double mitab_c_get_text_width( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_text_fgcolor( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_text_bgcolor( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_text_justification( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_text_spacing( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_text_linetype( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern void mitab_c_set_pen( IntPtr feature, int width, int pattern, int color );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_pen_color( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_pen_width( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern int mitab_c_get_pen_pattern( IntPtr feature );

		[DllImport("mitab.dll")]
		public static extern void mitab_c_set_brush( IntPtr feature,
			int fg_color, int bg_color, int pattern,
			int transparent );
		
		/// <summary>
		/// Get an object's brush foreground color property. Applies to region, ellipse and rectangle objects.
		/// </summary>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -