GIS开源库shapeLib的使用方法

转自:http://www.cnblogs.com/liongis/archive/2012/10/23/2736015.html

    近期研究了一下GIS开源库shapeLib读写ArcGIS数据的API函数,先整理一下,将各个API的用法介绍一下。

分为两个模块,shape API和DBF API,前者的读取.shp文件的空间几何信息,后者读取.dbf文件的属性信息。

Shape API:

Shape Types (shape类型)

shape文件的类型定义如下:

#define SHPT_NULL             02D Shape Types (pre ArcView 3.x):#define SHPT_POINT		1	Points#define SHPT_ARC		3	Arcs (Polylines, possible in parts)#define SHPT_POLYGON		5	Polygons (possible in parts)#define SHPT_MULTIPOINT	8	MultiPoint (related points)3D Shape Types (may include "measure" values for vertices):#define SHPT_POINTZ		11	#define SHPT_ARCZ		13#define SHPT_POLYGONZ		15#define SHPT_MULTIPOINTZ 	182D + Measure Types:#define SHPT_POINTM		21#define SHPT_ARCM		23#define SHPT_POLYGONM		25#define SHPT_MULTIPOINTM 	28Complex (TIN-like) with Z, and Measure:#define SHPT_MULTIPATCH 	31
 

SHPObject  (shape文件中包含的要素对象)

typedef struct{int		nSHPType;	//Shape Type (SHPT_* - see list above) 要素类型int		nShapeId; 	//Shape Number (-1 is unknown/unassigned) IDint		nParts;		//# of Parts (0 implies single part with no info) 要素有几个部分组成int		*panPartStart;  //Start Vertex of part 要素部分的起始点int		*panPartType;	//Part Type (SHPP_RING if not SHPT_MULTIPATCH) 各个部分的类型int		nVertices;	//Vertex list double	*padfX;		double	*padfY;double	*padfZ;		//(all zero if not provided)double	*padfM;		//(all zero if not provided)double	dfXMin;		//Bounds in X, Y, Z and M dimensionsdouble	dfYMin;double	dfZMin;double	dfMMin;double	dfXMax;double	dfYMax;double	dfZMax;double	dfMMax;} SHPObject;

SHPOpen()  

SHPHandle SHPOpen( const char * pszShapeFile, const char * pszAccess );pszShapeFile:		//shape文件的全路径pszAccess:		//打开方式 "rb" (read-only binary) and "rb+" (read/write binary) 		        

//打开shape文件,操作完必须调用后面的关闭。

SHPGetInfo()   //得到shape对象的信息

void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,double * padfMinBound, double * padfMaxBound );hSHP:			// shape文件的句柄 The handle previously returned by SHPOpen() or SHPCreate().pnEntities:		A pointer to an integer into which the number ofentities/structures should be placed.  May be NULL.pnShapetype:		A pointer to an integer into which the shapetypeof this file should be placed.  Shapefiles may containeither SHPT_POINT, SHPT_ARC, SHPT_POLYGON or SHPT_MULTIPOINT entities.  This may be NULL.padfMinBound:		The X, Y, Z and M minimum values will be placed intothis four entry array.  This may be NULL.padfMaxBound:		The X, Y, Z and M maximum values will be placed intothis four entry array.  This may be NULL.

SHPReadObject()  //读取每条记录中的信息

SHPObject *SHPReadObject( SHPHandle hSHP, int iShape );hSHP:			The handle previously returned by SHPOpen() or SHPCreate().iShape:		The entity number of the shape to read.  Entity numbers are between 0 and nEntities-1 (as returnedby SHPGetInfo()).

SHPClose()

void	SHPClose( SHPHandle hSHP );

SHPCreate()  //创建一个shape文件

SHPHandle SHPCreate( const char * pszShapeFile, int nShapeType );pszShapeFile:		//创建文件的名称nShapeType:		//类型,参加上面定义的类型

SHPCreateSimpleObject()   //创建简单要素对象,一般调用此方法

SHPObject * SHPCreateSimpleObject( int nSHPType, int nVertices, double *padfX, double * padfY, double *padfZ, );nSHPType:		The SHPT_ type of the object to be created, suchas SHPT_POINT, or SHPT_POLYGON.nVertices:		The number of vertices being passed in padfX,    padfY, and padfZ. padfX:		An array of nVertices X coordinates of the verticesfor this object.padfY:		An array of nVertices Y coordinates of the verticesfor this object.padfZ:		An array of nVertices Z coordinates of the verticesfor this object.  This may be NULL in which casethey are all assumed to be zero.
 

SHPCreateObject()  //创建复杂对象,参数中包含所有信息

SHPObject * SHPCreateObject( int nSHPType, int iShape,int nParts, int * panPartStart, int * panPartType,int nVertices, double *padfX, double * padfY, double *padfZ, double *padfM );nSHPType:		The SHPT_ type of the object to be created, suchas SHPT_POINT, or SHPT_POLYGON.iShape:		The shapeid to be recorded with this shape.nParts:		The number of parts for this object.  If this iszero for ARC, or POLYGON type objects, a single zero valued part will be created internally.panPartStart:		The list of zero based start vertices for the rings(parts) in this object.  The first should always bezero.  This may be NULL if nParts is 0.panPartType:		The type of each of the parts.  This is only meaningfulfor MULTIPATCH files.  For all other cases this maybe NULL, and will be assumed to be SHPP_RING.nVertices:		The number of vertices being passed in padfX,    padfY, and padfZ. padfX:		An array of nVertices X coordinates of the verticesfor this object.padfY:		An array of nVertices Y coordinates of the verticesfor this object.padfZ:		An array of nVertices Z coordinates of the verticesfor this object.  This may be NULL in which casethey are all assumed to be zero.padfM:		An array of nVertices M (measure values) of the vertices for this object.  This may be NULL in which case they are all assumed to be zero.

SHPComputeExtents()  //重新计算记录的取值范围

void SHPComputeExtents( SHPObject * psObject );psObject:		An existing shape object to be updated in place.

SHPWriteObject()  //向shape文件中添加一条记录,只有先添加了记录,才能添加属性信息

int SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject *psObject );hSHP:			The handle previously returned by SHPOpen("r+") or SHPCreate().iShape:		The entity number of the shape to write.  A value of-1 should be used for new shapes.  psObject:		The shape to write to the file. This should havebeen created with SHPCreateObject(), or SHPCreateSimpleObject().
 

SHPDestroyObject()  //删除对象

void SHPDestroyObject( SHPObject *psObject );psObject:		The object to deallocate.

SHPRewindObject()

int SHPRewindObject( SHPHandle hSHP, SHPObject *psObject );hSHP:                 The shapefile (not used at this time).psObject:		The object to deallocate.
This function will reverse any rings necessary in order to enforce the shapefile restrictions on the required order of inner and outer rings in the Shapefile specification. It returns TRUE if a change is made and FALSE if no change is made. Only polygon objects will be affected though any object may be passed.

前面介绍了shape API,接下来介绍 dBF API

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) should be used.

DBFCreate()

DBFHandle DBFCreate( const char * pszDBFFile );pszDBFFile:		The name of the xBase (.dbf) file to create.
//如果要创建一个完整的shape文件,首先要创建.shap文件,还要创建.dbf文件,两者缺一不可。

DBFGetFieldCount()  //得到字段的个数

int DBFGetFieldCount( DBFHandle hDBF );hDBF:		The access handle for the file to be queried, as returnedby DBFOpen(), or DBFCreate().

DBFGetRecordCount()

//得到记录的个数,应该和shape文件中的object的个数对应

int DBFGetRecordCount( DBFHandle hDBF );hDBF:		The access handle for the file to be queried, as returned byDBFOpen(), or DBFCreate().
 

DBFGetFieldIndex()  //通过字段名称得到字段的编号

 
int DBFGetFieldIndex( DBFHandle hDBF, const char *pszFieldName );hDBF:		The access handle for the file to be queried, as returned byDBFOpen(), or DBFCreate().
 

DBFGetFieldInfo()  //得到字段的信息,包括类型、长度等

 
DBFFieldType 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 should be a number between 0 and n-1, where n is the number fields on the file, asreturned by DBFGetFieldCount().pszFieldName:	If this pointer is not NULL the name of the requested fieldwill be written to this location.  The pszFieldName buffer should 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 isthe width in characters.  pnDecimals:	If this pointer is not NULL, the number of decimal placesprecision defined for the field will be returned.  This iszero for integer fields, or non-numeric fields.
 

DBFAddField()  //向DBF表中添加一个新的属性字段

 
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 benecessary to avoid some special characters in the field namessuch as spaces, or arithmetic operators.eType:	One of FTString, FTInteger or FTDouble in order to establishthe type of the new field.  Note that some valid xBase fieldtypes cannot be created such as date fields.nWidth:	The width of the field to be created.  For FTString fields thisestablishes the maximum length of string that can be stored.For FTInteger this establishes the number of digits of thelargest number that canbe represented.  For FTDouble fields this in combinationwith the nDecimals value establish the size, and precisionof the created field.nDecimals:    The number of decimal places to reserve for FTDouble fields.For all other field types this should be zero.  For instancewith nWidth=7, and nDecimals=3 numbers would be formattedsimilarly to `123.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 valueshould be read.iField:	The field within the selected record that should 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 valueshould be read.iField:	The field within the selected record that should 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 valueshould be read.iField:	The field within the selected record that should 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 valueshould be read.iField:	The field within the selected record that should 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 valueshould be written.iField:	The field within the selected record that should be written.nFieldValue:	The integer value that should 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 valueshould be written.iField:	The field within the selected record that should be written.dFieldValue:	The floating point value that should 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 valueshould be written.iField:	The field within the selected record that should 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 DBFWriteNULLAttribute( 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 valueshould be written.iField:	The field within the selected record that should be written.
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 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) should 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 of:

 

  • '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)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/352850.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux 升级 iphone,Linux 5.13 更新有望增加对苹果 M1 处理器的支持

IT之家 4 月 10 日消息 预计 Linux 5.13 将初步支持苹果 Silicon M1 处理器,不过可能还需要几年时间才能完全支持。虽然已经在苹果 Silicon M1 上运行,但这是通过一系列的补丁,单纯是为了 Linux 能够在 M1 设备上启动而已,而现在 …

201771010118马昕璐

第一部分 理论知识的学习 第三章Java基本程序设计结构 1 基本知识: (1)标识符:标识符由字母、下划线、美元符号和数字组成,且第一个符号不能为数字。Hello、$1234、程序名、www_123都是合法标识符。 标识符可用作类名…

Xshell显示中文乱码问题

转载自:http://www.blogjava.net/RoyPayne/archive/2011/12/21/366899.htmlXshell对于嵌入式开发来说,是个非常不错的工具。但或许都有过被中文显示为乱码的问题感觉有点不爽。解决方法其实很简单的,即把xshell编码方式改成UTF-8即可。 [文…

apache wicket_Apache Wicket:记住我的功能

apache wicket在Web应用程序中,很常见的是具有“记住我”功能,该功能使用户每次访问我们的网站时都能自动登录。 可以使用Spring Security来实现这种功能,但我认为将基于请求的身份验证框架与基于组件的Web框架一起使用并不是最好的主意。 这…

linux pap认证,配置PPP PAP 认证

配置PPP PAP 认证:1. 单向认证:R1启动pap R1为主验证方,R2为被验证方。r1(config)#inter s1/0r1(config-if)#ip add 202.146.0.1 255.255.255.0r1(config-if)#no shutdownr1(config-if)#encapsulation pppr1(config-if)#ppp authenticatin pa…

Shell编程关于Sha-Bang(#!)

转载自:http://blog.chinaunix.net/uid-26657936-id-3066136.html Q. #!的名字为什么叫Sha-Bang? A. Sha-Bang是Sharp和Bang的组合词。Sharp for #, Bang for ! 类似的情况是,C#通常被称为C SharpQ. Sha-Bang(#!)是不是注释?A. 不…

您应该保持联系的十大高级Java对话

在线讲座和视频是学习软件开发新事物的主要资源之一。 您可以找到Java专家与您分享他们的经验,而不必坐下来。 在下面的文章中,我们收集了10位我们最喜欢的演讲者和主题,我们相信每个Java开发人员都应该注意。 获取爆米花,坐下来…

c语言定时器作用,Go语言定时器实现原理及作用

对于任何一个正在运行的应用,如何获取准确的绝对时间都非常重要,但是在一个分布式系统中我们很难保证各个节点上绝对时间的一致性,哪怕通过 NTP 这种标准的对时协议也只能把时间的误差控制在毫秒级,所以相对时间在一个分布式系统中…

非常详细的/etc/passwd解释

root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin desktop:x:80:80:desktop:/var/lib/menu/kde:/sbin/nologin mengqc:x:500:500:mengqc:/home/mengqc:/bin/bash 在该文件中,每一行用户记录的各个数据段…

QT:基本知识(一);

注: 该博文为扩展型; 1) QString转换为LPCTSTR QString szStr; LPCTSTR str (LPWSTR)(szStr.utf16()); 2) 中文乱码解决; QTextCodec *pCodec QTextCode::codecForName("gb2312"); if(!pCodec) return ""; std…

c语言程序设计实训教材,C语言程序设计实训指导书

摘要:李建中等编著的这本《C语言程序设计实训指导书》为《C语言程序设计》的配套教材.全书共分4部分.第1部分主要介绍Visual C6.0的集成功能界面和操作;第2部分配合主教材的内容,设计了11个实验项目;第3部分对主教材每一章习题给出解答或指导;第4部分为全国计算机等…

SUID SGID

转载自:http://www.cnblogs.com/perseus/articles/2830397.html 如果你对SUID、SGID仍有迷惑可以好好参考一下! Copyright by kevintz.由于用户在UNIX下经常会遇到SUID、SGID的概念,而且SUID和SGID涉及到系统安全,所以用户也比较…

动态规划:LIS优化

对于1D/1D动态规划来说,理论时间复杂度都是O(n^2)的,这种动态规划一般都可以进行优化,贴一篇文章 https://wenku.baidu.com/view/e317b1020740be1e650e9a12.html 这里介绍最简单的一种,LIS的求法 其实就是二…

maven 版本号插件_Maven内部版本号插件–用法示例

maven 版本号插件假设我们需要向一些工件(jar,war等)添加内部版本号。 在这里,我想演示buildnumber-maven-plugin的用法。 这篇文章基于: http://mojo.codehaus.org/buildnumber-maven-plugin/usage.html http://www…

c语言程序设计课件第二章,c语言程序设计课件张元国 ISBN9787566300386 PPT第二章数据类型 运算符与表达式...

1、第2章 数据类型、运算符与表达式,语言的数据类型 常量与变量 运算符与表达式 不同类型数据间的转换,2.1语言的数据类型,数据是计算机程序处理的所有信息的总称,数值、字符、文本等都是数据,在各种程序设计中几乎都要使用和处理数据,程序设…

nowcoder172C 保护 (倍增lca+dfs序+主席树)

https://www.nowcoder.com/acm/contest/172/C (sbw大佬太强啦 orz) 先把每一个路径(x,y)分成(x,lca),(y,lca)两个路径,然后就能发现,对于某两个(直上直下的)路径a,b,b的下端点在a的下端点子树中…

添用户报错:useradd:警告:此主目录已经存在

转载自:http://blog.csdn.net/lele892207980/article/details/17239347 建立mysql用户、组 groupadd mysql useradd -g mysql mysql 然后删除 userdel mysql 再添用户和组加时,提示: useradd:警告:此主目录已经存在。…

专业本的C语言,以解决本专业问题为导向的C语言程序设计课程教学探索

以解决本专业问题为导向的C语言程序设计课程教学探索发布时间:2019-08-07 来源: 摘 要 针对C语言程序设计课程在计算机及其相关专业中存在的“狭义工具论”的教学现状,本着“以应用能力培养为目标、以计算思维为手段”的原则进行知识选取和教学内容、教学案例、教学…

HotSpot增量Java垃圾收集器

在我最近的博客文章“ 确定活动的HotSpot垃圾收集器”中 ,我描述了可用于确定HotSpot JVM (Java进程)正在使用的垃圾收集器(当从命令行参数(标志) 中看不出来)时可以使用的不同方法。传递给Java…

修改已存在用户的所属组(usermod用法)

转载自:http://blog.163.com/zhzh_lin/blog/static/40538715200771503221224/ 修改使用者帐号 名称 usermod - 修 改 使 用 者 帐 号 语法 usermod [-c comment] [-d home_dir [ -m]] [-e expire_date] [-f inactive_time] [-g initial_group] [-G group[,.…