📄 maptools.cs
字号:
/// <param name="adfX">An array of nVertices X coordinates of the vertices for this object.</param>
/// <param name="adfY">An array of nVertices Y coordinates of the vertices for this object.</param>
/// <param name="adfZ">An array of nVertices Z coordinates of the vertices for this object.
/// This may be NULL in which case they are all assumed to be zero.</param>
/// <returns>IntPtr to a SHPObject</returns>
/// <remarks>
/// The SHPDestroyObject() function should be used to free resources associated with an
/// object allocated with SHPCreateSimpleObject().
/// </remarks>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr SHPCreateSimpleObject(ShapeType shpType, int nVertices,
double[] adfX, double[] adfY, double[] adfZ);
/// <summary>
/// The SHPClose() function will close the .shp and .shx files, and flush all outstanding header
/// information to the files. It will also recover resources associated with the handle.
/// After this call the hSHP handle cannot be used again.
/// </summary>
/// <param name="hSHP">The handle previously returned by SHPOpen() or SHPCreate().</param>
/// <returns>void</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern void SHPClose(IntPtr hSHP);
/// <summary>
/// Translates a ShapeType.* constant into a named shape type (Point, PointZ, Polygon, etc.)
/// </summary>
/// <param name="shpType">ShapeType enum</param>
/// <returns>string</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern string SHPTypeName(ShapeType shpType);
/// <summary>
/// Translates a PartType enum into a named part type (Ring, Inner Ring, etc.)
/// </summary>
/// <param name="partType">PartType enum</param>
/// <returns>string</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern string SHPPartTypeName (PartType partType);
/* -------------------------------------------------------------------- */
/* Shape quadtree indexing API. */
/* -------------------------------------------------------------------- */
/// <summary>
/// Creates a quadtree index
/// </summary>
/// <param name="hSHP"></param>
/// <param name="nDimension"></param>
/// <param name="nMaxDepth"></param>
/// <param name="adfBoundsMin"></param>
/// <param name="adfBoundsMax"></param>
/// <returns>IntPtr</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr SHPCreateTree(IntPtr hSHP, int nDimension, int nMaxDepth,
double[] adfBoundsMin, double[] adfBoundsMax);
/// <summary>
/// Releases resources associated with quadtree
/// </summary>
/// <param name="hTree"></param>
/// <returns>void</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern void SHPDestroyTree(IntPtr hTree);
/// <summary>
///
/// </summary>
/// <param name="hTree"></param>
/// <param name="psObject"></param>
/// <returns>int</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern int SHPTreeAddShapeId(IntPtr hTree, IntPtr psObject);
/// <summary>
///
/// </summary>
/// <param name="hTree"></param>
/// <returns>void</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern void SHPTreeTrimExtraNodes(IntPtr hTree);
/// <summary>
///
/// </summary>
/// <param name="hTree"></param>
/// <param name="adfBoundsMin"></param>
/// <param name="adfBoundsMax"></param>
/// <param name="pnShapeCount"></param>
/// <returns>IntPtr</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr SHPTreeFindLikelyShapes(IntPtr hTree,
double[] adfBoundsMin, double[] adfBoundsMax, ref int pnShapeCount);
/// <summary>
///
/// </summary>
/// <param name="adfBox1Min"></param>
/// <param name="adfBox1Max"></param>
/// <param name="adfBox2Min"></param>
/// <param name="adfBox2Max"></param>
/// <param name="nDimension"></param>
/// <returns>int</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern int SHPCheckBoundsOverlap(double[] adfBox1Min, double[] adfBox1Max,
double[] adfBox2Min, double[] adfBox2Max, int nDimension);
/// <summary>
/// xBase field type enumeration
/// </summary>
public enum DBFFieldType
{
///<summary>String data type</summary>
FTString,
///<summary>Integer data type</summary>
FTInteger,
///<summary>Double data type</summary>
FTDouble,
///<summary>Logical data type</summary>
FTLogical,
///<summary>Invalid data type</summary>
FTInvalid,
/// <summary>Date data type</summary>
FTDate
};
/// <summary>
/// The DBFOpen() function should be used to establish access to an existing xBase format table file.
/// The returned DBFHandle is passed to other access functions, and DBFClose() should be invoked
/// to recover resources, and flush changes to disk when complete. The DBFCreate() function should
/// called to create new xBase files. As a convenience, DBFOpen() can be called with the name of a
/// .shp or .shx file, and it will figure out the name of the related .dbf file.
/// </summary>
/// <param name="szDBFFile">The name of the xBase (.dbf) file to access.</param>
/// <param name="szAccess">The fopen() style access string. At this time only "rb" (read-only binary)
/// and "rb+" (read/write binary) should be used.</param>
/// <returns>IntPtr</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr DBFOpen (string szDBFFile, string szAccess);
/// <summary>
/// The DBFCreate() function creates a new xBase format file with the given name,
/// and returns an access handle that can be used with other DBF functions.
/// The newly created file will have no fields, and no records.
/// Fields should be added with DBFAddField() before any records add written.
/// </summary>
/// <param name="szDBFFile">The name of the xBase (.dbf) file to create.</param>
/// <returns>IntPtr</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr DBFCreate (string szDBFFile);
/// <summary>
/// The DBFGetFieldCount() function returns the number of fields currently defined
/// for the indicated xBase file.
/// </summary>
/// <param name="hDBF">The access handle for the file to be queried, as returned by
/// DBFOpen(), or DBFCreate().</param>
/// <returns>int</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern int DBFGetFieldCount (IntPtr hDBF);
/// <summary>
/// The DBFGetRecordCount() function returns the number of records that exist on the xBase
/// file currently. Note that with shape files one xBase record exists for each shape in the
/// .shp/.shx files.
/// </summary>
/// <param name="hDBF">The access handle for the file to be queried, as returned by
/// DBFOpen(), or DBFCreate().</param>
/// <returns>int</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern int DBFGetRecordCount (IntPtr hDBF);
/// <summary>
/// The DBFAddField() function is used to add new fields to an existing xBase file opened with DBFOpen(),
/// or created with DBFCreate(). Note that fields can only be added to xBase files with no records,
/// though this is limitation of this API, not of the file format. Returns the field number of the
/// new field, or -1 if the addition of the field failed
/// </summary>
/// <param name="hDBF">The access handle for the file to be updated, as returned by DBFOpen(),
/// or DBFCreate().</param>
/// <param name="szFieldName">The name of the new field. At most 11 character will be used.
/// In order to use the xBase file in some packages it may be necessary to avoid some special
/// characters in the field names such as spaces, or arithmetic operators.</param>
/// <param name="eType">One of FTString, FTInteger, FTLogical, FTDate, or FTDouble in order to establish the
/// type of the new field. Note that some valid xBase field types cannot be created such as date fields.</param>
/// <param name="nWidth">The width of the field to be created. For FTString fields this establishes
/// the maximum length of string that can be stored. For FTInteger this establishes the number of
/// digits of the largest number that can be represented. For FTDouble fields this in combination
/// with the nDecimals value establish the size, and precision of the created field.</param>
/// <param name="nDecimals">The number of decimal places to reserve for FTDouble fields.
/// For all other field types this should be zero. For instance with nWidth=7, and nDecimals=3
/// numbers would be formatted similarly to `123.456'.</param>
/// <returns>int</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern int DBFAddField (IntPtr hDBF, string szFieldName,
DBFFieldType eType, int nWidth, int nDecimals);
/// <summary>
/// The DBFGetFieldInfo() returns the type of the requested field, which is one of the DBFFieldType
/// enumerated values. As well, the field name, and field width information can optionally be returned.
/// The field type returned does not correspond one to one with the xBase field types.
/// For instance the xBase field type for Date will just be returned as being FTInteger.
/// </summary>
/// <param name="hDBF">The access handle for the file to be queried, as returned by DBFOpen(),
/// or DBFCreate().</param>
/// <param name="iField">The field to be queried. This should be a number between 0 and n-1,
/// where n is the number fields on the file, as returned by DBFGetFieldCount().</param>
/// <param name="szFieldName">If this pointer is not NULL the name of the requested field
/// will be written to this location. The pszFieldName buffer should be at least 12 character
/// is size in order to hold the longest possible field name of 11 characters plus a terminating
/// zero character.</param>
/// <param name="pnWidth">If this pointer is not NULL, the width of the requested field will be
/// returned in the int pointed to by pnWidth. This is the width in characters. </param>
/// <param name="pnDecimals">If this pointer is not NULL, the number of decimal places precision
/// defined for the field will be returned. This is zero for integer fields, or non-numeric fields.</param>
/// <returns>DBFFieldType</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern DBFFieldType DBFGetFieldInfo (IntPtr hDBF, int iField,
StringBuilder szFieldName, ref int pnWidth, ref int pnDecimals);
/// <summary>
/// Returns the index of the field matching this name, or -1 on failure.
/// The comparison is case insensitive. However, lengths must match exactly.
/// </summary>
/// <param name="hDBF">The access handle for the file to be queried, as returned
/// by DBFOpen(), or DBFCreate().</param>
/// <param name="szFieldName">Name of the field to search for.</param>
/// <returns>int</returns>
[DllImport("shapelib.dll", CharSet=CharSet.Ansi)]
public static extern int DBFGetFieldIndex (IntPtr hDBF, string szFieldName);
/// <summary>
/// The DBFReadIntegerAttribute() will read the value of one field and return it as an integer.
/// </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>
/// 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 int DBFReadIntegerAttribute (IntPtr hDBF, int iShape, int iField);
[DllImport("shapelib.dll", CharSet=CharSet.Ansi, EntryPoint="DBFReadDateAttribute")]
private static extern int _DBFReadDateAttribute (IntPtr hDBF, int iShape, int iField);
/// <summary>
/// The DBFReadDateAttribute() will read the value of one field and return it as a System.DateTime value.
/// </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>
/// This can be used even with FTString fields, though the returned value will be zero if not
/// interpretable as a number.
/// </remarks>
public static DateTime DBFReadDateAttribute (IntPtr hDBF, int iShape, int iField)
{
string sDate = _DBFReadDateAttribute(hDBF, iShape, iField).ToString();
try
{
DateTime d = new DateTime(int.Parse(sDate.Substring(0,4)), int.Parse(sDate.Substring(4,2)),
int.Parse(sDate.Substring(6,2)));
return d;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -