📄 shapefil.h
字号:
#ifndef _SHAPEFILE_H_INCLUDED#define _SHAPEFILE_H_INCLUDED/****************************************************************************** * $Id: shapefil.h,v 1.26 2004/09/13 HHS Exp $ * * Project: Shapelib * Purpose: Primary include file for Shapelib. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2004, HHS * * This software is available under the following "MIT Style" license, * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This * option is discussed in more detail in shapelib.html. * * -- * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** */#include <stdio.h>#include <tchar.h>
#ifdef USE_DBMALLOC#include <dbmalloc.h>#endif#ifdef __cplusplusextern "C" {#endif/************************************************************************//* Configuration options. *//************************************************************************//* -------------------------------------------------------------------- *//* Should the DBFReadStringAttribute() strip leading and *//* trailing white space? *//* -------------------------------------------------------------------- */#define TRIM_DBF_WHITESPACE/* -------------------------------------------------------------------- *//* Should we write measure values to the Multipatch object? *//* Reportedly ArcView crashes if we do write it, so for now it *//* is disabled. *//* -------------------------------------------------------------------- */#define DISABLE_MULTIPATCH_MEASURE/* -------------------------------------------------------------------- *//* SHPAPI_CALL *//* *//* The following two macros are present to allow forcing *//* various calling conventions on the Shapelib API. *//* *//* To force __stdcall conventions (needed to call Shapelib *//* from Visual Basic and/or Dephi I believe) the makefile could *//* be modified to define: *//* *//* /DSHPAPI_CALL=__stdcall *//* *//* If it is desired to force export of the Shapelib API without *//* using the shapelib.def file, use the following definition. *//* *//* /DSHAPELIB_DLLEXPORT *//* *//* To get both at once it will be necessary to hack this *//* include file to define: *//* *//* #define SHPAPI_CALL __declspec(dllexport) __stdcall *//* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall *//* *//* The complexity of the situtation is partly caused by the *//* peculiar requirement of Visual C++ that __stdcall appear *//* after any "*"'s in the return value of a function while the *//* __declspec(dllexport) must appear before them. *//* -------------------------------------------------------------------- */#define SHAPELIB_DLLEXPORT
#ifdef SHAPELIB_DLLEXPORT# define SHPAPI_CALL __declspec(dllexport) # define SHPAPI_CALL1(x) __declspec(dllexport) x#endif#ifndef SHPAPI_CALL# define SHPAPI_CALL#endif#ifndef SHPAPI_CALL1# define SHPAPI_CALL1(x) x SHPAPI_CALL#endif /************************************************************************//* SHP Support. *//************************************************************************/typedef struct{ FILE *fpSHP; FILE *fpSHX; int nShapeType; /* SHPT_* */ int nFileSize; /* SHP file */ int nRecords; int nMaxRecords; int *panRecOffset; int *panRecSize; double adBoundsMin[4]; double adBoundsMax[4]; int bUpdated; unsigned char *pabyRec; int nBufSize;} SHPInfo;typedef SHPInfo * SHPHandle;/* -------------------------------------------------------------------- *//* Shape types (nSHPType) *//* -------------------------------------------------------------------- */#define SHPT_NULL 0#define SHPT_POINT 1#define SHPT_ARC 3#define SHPT_POLYGON 5#define SHPT_MULTIPOINT 8#define SHPT_POINTZ 11#define SHPT_ARCZ 13#define SHPT_POLYGONZ 15#define SHPT_MULTIPOINTZ 18#define SHPT_POINTM 21#define SHPT_ARCM 23#define SHPT_POLYGONM 25#define SHPT_MULTIPOINTM 28#define SHPT_MULTIPATCH 31/* -------------------------------------------------------------------- *//* Part types - everything but SHPT_MULTIPATCH just uses *//* SHPP_RING. *//* -------------------------------------------------------------------- */#define SHPP_TRISTRIP 0#define SHPP_TRIFAN 1#define SHPP_OUTERRING 2#define SHPP_INNERRING 3#define SHPP_FIRSTRING 4#define SHPP_RING 5/* -------------------------------------------------------------------- *//* SHPObject - represents on shape (without attributes) read *//* from the .shp file. *//* -------------------------------------------------------------------- */typedef struct{ int nSHPType; int nShapeId; /* -1 is unknown/unassigned */ int nParts; int *panPartStart; int *panPartType; int nVertices; double *padfX; double *padfY; double *padfZ; double *padfM; double dfXMin; double dfYMin; double dfZMin; double dfMMin; double dfXMax; double dfYMax; double dfZMax; double dfMMax;} SHPObject;/* -------------------------------------------------------------------- *//* SHP API Prototypes *//* -------------------------------------------------------------------- */SHPAPI_CALL SHPHandle SHPOpen( LPCTSTR pszShapeFile, LPCTSTR pszAccess );SHPAPI_CALL SHPHandle SHPCreate( LPCTSTR pszShapeFile, int nShapeType );SHPAPI_CALL void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType, double * padfMinBound, double * padfMaxBound );SHPAPI_CALL SHPObject * SHPReadObject( SHPHandle hSHP, int iShape );
SHPAPI_CALL BOOL
SHPReadObjectBounds( SHPHandle psSHP, SHPObject *psShape, int hEntity );
SHPAPI_CALL int SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );SHPAPI_CALL void SHPDestroyObject( SHPObject * psObject );SHPAPI_CALL void SHPComputeExtents( SHPObject * psObject );SHPAPI_CALL SHPObject * SHPCreateObject( int nSHPType, int nShapeId, int nParts, int * panPartStart, int * panPartType, int nVertices, double * padfX, double * padfY, double * padfZ, double * padfM );SHPAPI_CALL SHPObject * SHPCreateSimpleObject( int nSHPType, int nVertices, double * padfX, double * padfY, double * padfZ );SHPAPI_CALL int SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );SHPAPI_CALL void SHPClose( SHPHandle hSHP );SHPAPI_CALL LPCTSTR SHPTypeName( int nSHPType );SHPAPI_CALL LPCTSTR SHPPartTypeName( int nPartType );/* -------------------------------------------------------------------- *//* Shape quadtree indexing API. *//* -------------------------------------------------------------------- *//* this can be two or four for binary or quad tree */#define MAX_SUBNODE 4typedef struct shape_tree_node{ /* region covered by this node */ double adfBoundsMin[4]; double adfBoundsMax[4]; /* list of shapes stored at this node. The papsShapeObj pointers or the whole list can be NULL */ int nShapeCount; int *panShapeIds; SHPObject **papsShapeObj;
int nSubNodes; struct shape_tree_node *apsSubNode[MAX_SUBNODE]; } SHPTreeNode;typedef struct{ SHPHandle hSHP; int nMaxDepth; int nDimension; SHPTreeNode *psRoot;} SHPTree;SHPAPI_CALL SHPTree * SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth, double *padfBoundsMin, double *padfBoundsMax );SHPAPI_CALL void SHPDestroyTree( SHPTree * hTree );SHPAPI_CALL int SHPWriteTree( SHPTree *hTree, const TCHAR * pszFilename );SHPAPI_CALL SHPTree SHPReadTree( const TCHAR * pszFilename );SHPAPI_CALL int SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );SHPAPI_CALL int SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );SHPAPI_CALL int SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );SHPAPI_CALL void SHPTreeTrimExtraNodes( SHPTree * hTree );SHPAPI_CALL int * SHPTreeFindLikelyShapes( SHPTree * hTree, double * padfBoundsMin, double * padfBoundsMax, int * );SHPAPI_CALL int SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
SHPAPI_CALL void SHPTreeIndexFree(void * pIndex);
/************************************************************************//* DBF Support. *//************************************************************************/typedef struct{ FILE *fp; int nRecords; int nRecordLength; int nHeaderLength; int nFields; int *panFieldOffset; int *panFieldSize; int *panFieldDecimals; char *pachFieldType; char *pszHeader; int nCurrentRecord; int bCurrentRecordModified; char *pszCurrentRecord; int bNoHeader; int bUpdated;} DBFInfo;typedef DBFInfo * DBFHandle;typedef enum { FTString, FTInteger, FTDouble, FTLogical, FTInvalid} DBFFieldType;#define XBASE_FLDHDR_SZ 32SHPAPI_CALL DBFHandle DBFOpen( const TCHAR * pszDBFFile, const TCHAR * pszAccess );SHPAPI_CALL DBFHandle DBFCreate( const TCHAR * pszDBFFile );SHPAPI_CALL int DBFGetFieldCount( DBFHandle psDBF );SHPAPI_CALL int DBFGetRecordCount( DBFHandle psDBF );SHPAPI_CALL int DBFAddField( DBFHandle hDBF, const TCHAR * pszFieldName, DBFFieldType eType, int nWidth, int nDecimals );SHPAPI_CALL DBFFieldType DBFGetFieldInfo( DBFHandle psDBF, int iField, TCHAR * pszFieldName, int * pnWidth, int * pnDecimals );SHPAPI_CALL int DBFGetFieldIndex(DBFHandle psDBF, const TCHAR *pszFieldName);SHPAPI_CALL int DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );SHPAPI_CALL double DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );SHPAPI_CALL const TCHAR * DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );SHPAPI_CALL const TCHAR * DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );SHPAPI_CALL int DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );SHPAPI_CALL int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, int nFieldValue );SHPAPI_CALL int DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField, double dFieldValue );SHPAPI_CALL int DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField, const TCHAR * pszFieldValue );SHPAPI_CALL int DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );SHPAPI_CALL int DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField, const TCHAR lFieldValue);SHPAPI_CALL int DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, void * pValue );SHPAPI_CALL const char *
DBFReadTuple(DBFHandle psDBF, int hEntity );
SHPAPI_CALL int
DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );SHPAPI_CALL DBFHandle DBFCloneEmpty(DBFHandle psDBF, const TCHAR * pszFilename ); SHPAPI_CALL void DBFClose( DBFHandle hDBF );SHPAPI_CALL char DBFGetNativeFieldType( DBFHandle hDBF, int iField );
SHPAPI_CALL int WtoC(WCHAR * pwch, char * pchr);
SHPAPI_CALL int CtoW(char * pchr, WCHAR * pwch);
#ifdef __cplusplus}#endif#endif /* ndef _SHAPEFILE_H_INCLUDED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -