How to Use shapelib, an open-source GIS Library (2)

Source: Internet
Author: User
Tags truncated

The shape API is introduced earlier, and the dbf api is introduced later.

Dbfopen ()
 
Dbfhandle dbfopen (const char * pszdbffile, const char * pszaccess); pszdbffile: the name of the xbase (. DBF) file to access. pszaccess: The fopen () style access string. at this time only "rb" (read-only binary) and "RB +" (read/write binary) shocould be used.
Dbfcreate ()
 
Dbfhandle dbfcreate (const char * pszdbffile); pszdbffile: the name of the xbase (. DBF) file to create.
 
// If you want to create a complete shape file, you must first create the. shap file and the. DBF file. Both are indispensable.
Dbfgetfieldcount () // obtain the number of fields
Int dbfgetfieldcount (dbfhandle hdbf); hdbf: the access handle for the file to be queried, as returned by dbfopen (), or dbfcreate ().
Dbfgetrecordcount () // Obtain the number of records, which must correspond to the number of objects in the shape file.
 
Int dbfgetrecordcount (dbfhandle hdbf); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate ().
 
 
Dbfgetfieldindex () // obtain the ID of a field by field name
 
 
 
Int dbfgetfieldindex (dbfhandle hdbf, const char * pszfieldname); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate ().
 
 
Dbfgetfieldinfo () // obtain the field information, including the type and length.
 
Export dbfgetfieldinfo (dbfhandle hdbf, int ifield, char * pszfieldname, int * pnwidth, int * pndecimals); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate (). ifield: The field to be queried. this shoshould be a number between 0 and n-1, where N is the number fields on the file, as returned by dbfgetfieldcount (). pszfieldname: If this pointer is not null the name of the requested fieldwill be written to this location. the pszfieldname buffer shocould be at least 12 character is size in order to holdthe longest possible field name of 11 characters plus a terminating zero character. pnwidth: If this pointer is not null, the width of the requested fieldwill be returned in the int pointed to by pnwidth. this is the width in characters. 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.
 
Dbfaddfield () // Add a new attribute field to the DBF table
 
 
Int dbfaddfield (dbfhandle hdbf, const char * pszfieldname, dbffieldtype etype, int nwidth, int ndecimals); hdbf: the access handle for the file to be updated, as returned bydbfopen (), or dbfcreate (). pszfieldname: 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. etype: One of ftstring, ftinteger 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. 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. ndecimals: the number of decimal places to reserve for ftdouble fields. for all other field types this shoshould be zero. for instance with nwidth = 7, and ndecimals = 3 numbers wocould be formatted similarly to '2017. 456 '.
 
Dbfreadintegerattribute ()
 
 
 
Int dbfreadintegerattribute (dbfhandle hdbf, int ishape, int ifield); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) from which the field value shocould be read. ifield: The field within the selected record that shocould be read.
Dbfreaddoubleattribute ()
 
Double dbfreaddoubleattribute (dbfhandle hdbf, int ishape, int ifield); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) from which the field value shocould be read. ifield: The field within the selected record that shocould be read.
Dbfreadstringattribute ()
 
Const char * dbfreadstringattribute (dbfhandle hdbf, int ishape, int ifield); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) from which the field value shocould be read. ifield: The field within the selected record that shocould be read.
Dbfisattributenull ()
 
Int dbfisattributenull (dbfhandle hdbf, int ishape, int ifield); hdbf: the access handle for the file to be queried, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) from which the field value shocould be read. ifield: The field within the selected record that shocould be read.
Dbfwriteintegerattribute
Int dbfwriteintegerattribute (dbfhandle hdbf, int ishape, int ifield, int nfieldvalue); hdbf: the access handle for the file to be written, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) to which the field value shocould be written. ifield: The field within the selected record that shocould be written. nfieldvalue: the integer value that shoshould be written.
Dbfwritedoubleattribute ()
Int dbfwritedoubleattribute (dbfhandle hdbf, int ishape, int ifield, double dfieldvalue); hdbf: the access handle for the file to be written, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) to which the field value shocould be written. ifield: The field within the selected record that shocould be written. dfieldvalue: The floating point value that shoshould be written.
 
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.

 

Dbfwritestringattribute ()
Int dbfwritestringattribute (dbfhandle hdbf, int ishape, int ifield, const char * pszfieldvalue); hdbf: the access handle for the file to be written, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) to which the field value shocould be written. ifield: The field within the selected record that shocould be written. pszfieldvalue: the string to be written to the field.
 
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.

 

Dbfwritenullattribute ()
Int dbfwritenullattrield (dbfhandle hdbf, int ishape, int ifield); hdbf: the access handle for the file to be written, as returned bydbfopen (), or dbfcreate (). ishape: The Record Number (shape number) to which the field value shocould be written. ifield: The field within the selected record that shocould be written.
 
The dbfwritenullattribute () function is used to clear the indicated field to a null value. in. DBF file this is represented by setting the entire field to spaces. if the write succeeds the value true willbe returned, otherwise false will be returned.

 

Dbfclose ()
 
Void dbfclose (dbfhandle hdbf); hdbf: the access handle for the file to be closed.
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) shocould not be used again with the dbf api after calling dbfclose ().

 

Dbfgetnativefieldtype ()
 
Char dbfgetnativefieldtype (dbfhandle hdbf, int ifield); hdbf: the access handle for the file. ifield: The field index to query.
 
This function returns the DBF type code of the indicated field. It will be one:

 

    • 'C' (string)
    • 'D' (date)
    • 'F' (float)
    • 'N' (numeric, with or without decimal)
    • 'L' (logical)
    • 'M' (Memo: 10 digits. DBT block PTR)
    • ''(Field out of range)
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.