You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
9.9 KiB
C

1 month ago
//////////////////////////////////////////////////////////////////////////////
//<2F>ļ<EFBFBD> ShapeFile.h
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>:
//
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д: 2005-12-07
/////////////////////////////////////////////////////////////////////////////
#ifndef _SHAPEFILE_H_INCLUDED
#define _SHAPEFILE_H_INCLUDED
#include ".\otherformat.h"
namespace NFormatReader
{
namespace NShape
{
/* -------------------------------------------------------------------- */
/* 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
/************************************************************************/
/* SHP Support. */
/************************************************************************/
typedef struct __SHPInfo
{
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_POLYLINE 3
#define SHPT_POLYGON 5
#define SHPT_MULTIPOINT 8
#define SHPT_POINTZ 11
#define SHPT_POLYLINEZ 13
#define SHPT_POLYGONZ 15
#define SHPT_MULTIPOINTZ 18
#define SHPT_POINTM 21
#define SHPT_POLYLINEM 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 __SHPObject
{
int nSHPType;
int nShapeId; /* -1 is unknown/unassigned */
int nParts; //<2F>ֶ<EFBFBD><D6B6><EFBFBD>
int *panPartStart;
int *panPartType;
int nVertices; //<2F>ܵĵ<DCB5><C4B5><EFBFBD>
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 */
/* -------------------------------------------------------------------- */
class AFX_EXT_CLASS CShapeFile : public COtherFormat
{
public:
CShapeFile(void);
virtual ~CShapeFile(void);
int Read(LPCTSTR lpszPathName);
SHPHandle SHPOpen( const char * pszShapeFile, const char * pszAccess );
SHPHandle SHPCreate( const char * pszShapeFile, int nShapeType );
void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType, double * padfMinBound, double * padfMaxBound );
SHPObject* SHPReadObject( SHPHandle hSHP, int iShape );
int SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
int SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
void SHPWriteHeader( SHPHandle hSHP );
void SHPClose( SHPHandle hSHP );
void SHPDestroyObject( SHPObject * psObject );
SHPObject* SHPCreateObject( int nSHPType, int nShapeId,
int nParts, int * panPartStart, int * panPartType, int nVertices,
double * padfX, double * padfY, double * padfZ, double * padfM );
SHPObject* SHPCreateSimpleObject( int nSHPType, int nVertices, double * padfX, double * padfY, double * padfZ );
void SHPComputeExtents( SHPObject * psObject );
const char* SHPTypeName( int nSHPType );
const char* SHPPartTypeName( int nPartType );
};
///* -------------------------------------------------------------------- */
///* Shape quadtree indexing API. */
///* -------------------------------------------------------------------- */
//
///* this can be two or four for binary or quad tree */
//#define MAX_SUBNODE 4
//
//typedef 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;
//
//class CShapeTree
//{
//public:
// SHPTree* SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth, double *padfBoundsMin, double *padfBoundsMax );
// void SHPDestroyTree( SHPTree * hTree );
//
// int SHPWriteTree( SHPTree *hTree, const char * pszFilename );
// SHPTree SHPReadTree( const char * pszFilename );
//
// int SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
// int SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
// int SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
//
// void SHPTreeTrimExtraNodes( SHPTree * hTree );
//
// int* SHPTreeFindLikelyShapes( SHPTree * hTree, double * padfBoundsMin, double * padfBoundsMax, int * );
// int SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
//};
/************************************************************************/
/* DBF Support. */
/************************************************************************/
typedef struct __DBFInfo
{
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 __DBFFieldType
{
FTString,
FTInteger,
FTDouble,
FTLogical,
FTInvalid
} DBFFieldType;
#define XBASE_FLDHDR_SZ 32
class CShapeDBF
{
public:
CShapeDBF(void);
virtual ~CShapeDBF(void);
DBFHandle DBFOpen( const char * pszDBFFile, const char * pszAccess );
DBFHandle DBFCreate( const char * pszDBFFile );
int DBFGetFieldCount( DBFHandle psDBF );
int DBFGetRecordCount( DBFHandle psDBF );
int DBFAddField( DBFHandle hDBF, const char * pszFieldName, DBFFieldType eType, int nWidth, int nDecimals );
DBFFieldType DBFGetFieldInfo( DBFHandle psDBF, int iField, char * pszFieldName, int * pnWidth, int * pnDecimals );
int DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
int DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
double DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
const char* DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
const char* DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
int DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, int nFieldValue );
int DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField, double dFieldValue );
int DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField, const char * pszFieldValue );
int DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
int DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField, const char lFieldValue);
int DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, void * pValue );
const char* DBFReadTuple(DBFHandle psDBF, int hEntity );
int DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
DBFHandle DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
void DBFClose( DBFHandle hDBF );
void DBFUpdateHeader( DBFHandle hDBF );
char DBFGetNativeFieldType( DBFHandle hDBF, int iField );
void* DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField, char chReqType );
int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField, void * pValue );
void DBFFlushRecord(DBFHandle psDBF);
void DBFWriteHeader(DBFHandle psDBF);
};
};
};
extern "C"
{
void SwapWord( int length, void * wordP );
void * SfRealloc( void * pMem, int nNewSize );
};
using namespace NShape;
#endif /* ndef _SHAPEFILE_H_INCLUDED */