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

📄 maptools.cs

📁 包含详细例子的c#创建shape文件的开源码
💻 CS
📖 第 1 页 / 共 3 页
字号:
			}
			catch
			{
				return new DateTime(0);
			}
		}

		/// <summary>
		/// The DBFReadDoubleAttribute() will read the value of one field and return it as a double. 
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) from which the field value should be read.</param>
		/// <param name="iField">The field within the selected record that should be read.</param>
		/// <returns>double</returns>
		/// <remarks>
		/// This can be used even with FTString fields, though the returned value will be zero if not 
		/// interpretable as a number.
		/// </remarks>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern double DBFReadDoubleAttribute (IntPtr hDBF, int iShape, int iField);

		/// <summary>
		/// The DBFReadStringAttribute() will read the value of one field and return it as a string. 
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) from which the field value should be read.</param>
		/// <param name="iField">The field within the selected record that should be read.</param>
		/// <returns>string</returns>
		/// <remarks>
		/// This function may be used on any field type (including FTInteger and FTDouble) and will 
		/// return the string representation stored in the .dbf file. The returned pointer is to an 
		/// internal buffer which is only valid untill the next DBF function call. It's contents may 
		/// be copied with normal string functions such as strcpy(), or strdup(). If the 
		/// TRIM_DBF_WHITESPACE macro is defined in shapefil.h (it is by default) then all leading and 
		/// trailing space (ASCII 32) characters will be stripped before the string is returned.
		/// </remarks>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern string DBFReadStringAttribute (IntPtr hDBF, int iShape, int iField);

		[DllImport("shapelib.dll", CharSet=CharSet.Ansi, EntryPoint="DBFReadLogicalAttribute")]
		private static extern string _DBFReadLogicalAttribute (IntPtr hDBF, int iShape, int iField);
		/// <summary>
		/// The DBFReadLogicalAttribute() will read the value of one field and return it as a boolean. 
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) from which the field value should be read.</param>
		/// <param name="iField">The field within the selected record that should be read.</param>
		/// <returns>bool</returns>
		/// <remarks>
		/// This can be used with FTString fields, in which case it returns TRUE if the string="T";
		/// otherwise it returns FALSE.
		/// </remarks>
		public static bool DBFReadLogicalAttribute (IntPtr hDBF, int iShape, int iField)
		{
			return (_DBFReadLogicalAttribute(hDBF, iShape, iField)=="T");
		}

		/// <summary>
		/// This function will return TRUE if the indicated field is NULL valued otherwise FALSE. 
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) from which the field value should be read.</param>
		/// <param name="iField">The field within the selected record that should be read.</param>
		/// <returns>int</returns>
		/// <remarks>
		/// Note that NULL fields are represented in the .dbf file as having all spaces in the field. 
		/// Reading NULL fields will result in a value of 0.0 or an empty string with the other 
		/// DBFRead*Attribute() functions.
		/// </remarks>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFIsAttributeNULL (IntPtr hDBF, int iShape, int iField);

		/// <summary>
		/// The DBFWriteIntegerAttribute() function is used to write a value to a numeric field 
		/// (FTInteger, or FTDouble). If the write succeeds the value TRUE will be returned, 
		/// otherwise FALSE will be returned. If the value is too large to fit in the field, 
		/// it will be truncated and FALSE returned.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <param name="nFieldValue">The integer value that should be written.</param>
		/// <returns>int</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFWriteIntegerAttribute (IntPtr hDBF, int iShape, 
			int iField, int nFieldValue);

		/// <summary>
		/// Write an attribute record to the file, but without any reformatting based on type.  
		/// The provided buffer is written as is to the field position in the record. 
		/// If the write succeeds the value TRUE will be returned, otherwise FALSE will be returned. 
		/// If the value is too large to fit in the field, it will be truncated and FALSE returned.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <param name="pValue">pointer to the value</param>
		/// <returns>int</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFWriteAttributeDirectly (IntPtr hDBF, int iShape, 
			int iField, IntPtr pValue);

		[DllImport("shapelib.dll", CharSet=CharSet.Ansi, EntryPoint="DBFWriteDateAttribute")]
		private static extern int _DBFWriteDateAttribute (IntPtr hDBF, int iShape, 
			int iField, int nFieldValue);
		/// <summary>
		/// The DBFWriteDateAttribute() function is used to write a value to a date field 
		/// (FTDate). If the write succeeds the value TRUE will be returned, 
		/// otherwise FALSE will be returned. If the value is too large to fit in the field, 
		/// it will be truncated and FALSE returned. 
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <param name="nFieldValue">The System.DateTime date value that should be written.</param>
		/// <returns>int</returns>
		public static int DBFWriteDateAttribute (IntPtr hDBF, int iShape, 
			int iField, DateTime nFieldValue)
		{
			return _DBFWriteDateAttribute(hDBF, iShape, iField, int.Parse(nFieldValue.ToString("yyyyMMdd")));
		}

		/// <summary>
		/// The DBFWriteDoubleAttribute() function is used to write a value to a numeric field 
		/// (FTInteger, or FTDouble). If the write succeeds the value TRUE will be returned, 
		/// otherwise FALSE will be returned. If the value is too large to fit in the field, 
		/// it will be truncated and FALSE returned.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <param name="dFieldValue">The floating point value that should be written.</param>
		/// <returns>int</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFWriteDoubleAttribute (IntPtr hDBF, int iShape, 
			int iField, double dFieldValue);

		/// <summary>
		/// The DBFWriteStringAttribute() function is used to write a value to a string field (FString). 
		/// If the write succeeds the value TRUE willbe returned, otherwise FALSE will be returned. 
		/// If the value is too large to fit in the field, it will be truncated and FALSE returned.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <param name="szFieldValue">The string to be written to the field.</param>
		/// <returns>int</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFWriteStringAttribute (IntPtr hDBF, int iShape, 
			int iField, string szFieldValue);

		/// <summary>
		/// The DBFWriteNULLAttribute() function is used to clear the indicated field to a NULL value. 
		/// In the .dbf file this is represented by setting the entire field to spaces. If the write 
		/// succeeds the value TRUE will be returned, otherwise FALSE will be returned.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <returns>int</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFWriteNULLAttribute (IntPtr hDBF, int iShape, int iField);

		[DllImport("shapelib.dll", CharSet=CharSet.Ansi, EntryPoint="DBFWriteLogicalAttribute")]
		private static extern int _DBFWriteLogicalAttribute (IntPtr hDBF, int iShape, 
			int iField, char lFieldValue);
		/// <summary>
		/// The DBFWriteLogicalAttribute() function is used to write a boolean value to a logical field 
		/// (FTLogical). If the write succeeds the value TRUE will be returned, 
		/// otherwise FALSE will be returned.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be written, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="iShape">The record number (shape number) to which the field value should be written.</param>
		/// <param name="iField">The field within the selected record that should be written.</param>
		/// <param name="bFieldValue">The boolean value to be written to the field.</param>
		/// <returns>int</returns>
		public static int DBFWriteLogicalAttribute (IntPtr hDBF, int iShape, int iField, bool bFieldValue)
		{
			if (bFieldValue)
				return _DBFWriteLogicalAttribute(hDBF, iShape, iField, 'T');
			else
				return _DBFWriteLogicalAttribute(hDBF, iShape, iField, 'F');
		}

		/// <summary>
		/// Reads the attribute fields of a record.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="hEntity">The entity (record) number to be read</param>
		/// <returns>IntPtr</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern IntPtr DBFReadTuple (IntPtr hDBF, int hEntity);

		/// <summary>
		/// Writes an attribute record to the file.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="hEntity">The zero-based entity (record) number to be written.  If hEntity equals 
		/// the number of records a new record is appended.</param>
		/// <param name="pRawTuple">Pointer to the tuple to be written</param>
		/// <returns>int</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern int DBFWriteTuple (IntPtr hDBF, int hEntity, IntPtr pRawTuple);

		/// <summary>
		/// Copies the data structure of an xBase file to another xBase file.  
		/// Data are not copied.  Use Read/WriteTuple functions to selectively copy data.
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be queried, as returned by 
		/// DBFOpen(), or DBFCreate().</param>
		/// <param name="szFilename">The name of the xBase (.dbf) file to create.</param>
		/// <returns>IntPtr</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern IntPtr DBFCloneEmpty (IntPtr hDBF, string szFilename);

		/// <summary>
		/// The DBFClose() function will close the indicated xBase file (opened with DBFOpen(), 
		/// or DBFCreate()), flushing out all information to the file on disk, and recovering 
		/// any resources associated with having the file open. The file handle (hDBF) should not 
		/// be used again with the DBF API after calling DBFClose().
		/// </summary>
		/// <param name="hDBF">The access handle for the file to be closed.</param>
		/// <returns>void</returns>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern void DBFClose (IntPtr hDBF);

		
		/// <summary>
		/// This function returns the DBF type code of the indicated field.
		/// </summary>
		/// <param name="hDBF">The access handle for the file.</param>
		/// <param name="iField">The field index to query.</param>
		/// <returns>sbyte</returns>
		/// <remarks>
		/// Return value will be one of:
		/// <list type="bullet">
		/// <item><term>C</term><description>String</description></item>
		/// <item><term>D</term><description>Date</description></item>
		/// <item><term>F</term><description>Float</description></item>
		/// <item><term>N</term><description>Numeric, with or without decimal</description></item>
		/// <item><term>L</term><description>Logical</description></item>
		/// <item><term>M</term><description>Memo: 10 digits .DBT block ptr</description></item>
		/// <item><term> </term><description>field out of range</description></item>
		/// </list>
		/// </remarks>
		[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
		public static extern sbyte DBFGetNativeFieldType (IntPtr hDBF, int iField);

		/// <summary>
		/// private constructor:  no instantiation needed or permitted
		/// </summary>
		private ShapeLib(){} 
	}
}

⌨️ 快捷键说明

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