GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
|
#include <grass/shapefil.h>
#include <math.h>
#include <limits.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Go to the source code of this file.
Macros | |
#define | CPL_UNUSED |
#define | FALSE 0 |
#define | TRUE 1 |
#define | ByteCopy(a, b, c) memcpy( b, a, c ) |
#define | MIN(a, b) ((a<b) ? a : b) |
#define | MAX(a, b) ((a>b) ? a : b) |
Typedefs | |
typedef unsigned char | uchar |
typedef unsigned int | int32 |
Functions | |
void SHPAPI_CALL | SHPWriteHeader (SHPHandle psSHP) |
SHPHandle SHPAPI_CALL | SHPOpen (const char *pszLayer, const char *pszAccess) |
SHPHandle SHPAPI_CALL | SHPOpenLL (const char *pszLayer, const char *pszAccess, SAHooks *psHooks) |
SHPHandle SHPAPI_CALL | SHPOpenLLEx (const char *pszLayer, const char *pszAccess, SAHooks *psHooks, int bRestoreSHX) |
int SHPAPI_CALL | SHPRestoreSHX (const char *pszLayer, const char *pszAccess, SAHooks *psHooks) |
void SHPAPI_CALL | SHPClose (SHPHandle psSHP) |
void SHPAPI_CALL | SHPSetFastModeReadObject (SHPHandle hSHP, int bFastMode) |
void SHPAPI_CALL | SHPGetInfo (SHPHandle psSHP, int *pnEntities, int *pnShapeType, double *padfMinBound, double *padfMaxBound) |
SHPHandle SHPAPI_CALL | SHPCreate (const char *pszLayer, int nShapeType) |
SHPHandle SHPAPI_CALL | SHPCreateLL (const char *pszLayer, int nShapeType, SAHooks *psHooks) |
void SHPAPI_CALL | SHPComputeExtents (SHPObject *psObject) |
SHPObject SHPAPI_CALL1 * | SHPCreateObject (int nSHPType, int nShapeId, int nParts, const int *panPartStart, const int *panPartType, int nVertices, const double *padfX, const double *padfY, const double *padfZ, const double *padfM){ SHPObject *psObject;int i, bHasM, bHasZ;psObject=(SHPObject *) calloc(1, sizeof(SHPObject) |
if (nSHPType==SHPT_ARCM||nSHPType==SHPT_POINTM||nSHPType==SHPT_POLYGONM||nSHPType==SHPT_MULTIPOINTM) | |
if (nVertices > 0) | |
SHPComputeExtents (psObject) | |
return (psObject) | |
SHPObject SHPAPI_CALL1 * | SHPCreateSimpleObject (int nSHPType, int nVertices, const double *padfX, const double *padfY, const double *padfZ){ return(SHPCreateObject(nSHPType, -1, 0, NULL, NULL, nVertices, padfX, padfY, padfZ, NULL) |
int SHPAPI_CALL | SHPWriteObject (SHPHandle psSHP, int nShapeId, SHPObject *psObject) |
SHPObject SHPAPI_CALL1 * | SHPReadObject (SHPHandle psSHP, int hEntity){ int nEntitySize, nRequiredSize;SHPObject *psShape;char szErrorMsg[128];int nSHPType;int nBytesRead;if(hEntity< 0||hEntity >=psSHP->nRecords) return(NULL |
if (psSHP->panRecOffset[hEntity]==0 &&psSHP->fpSHX !=NULL) | |
if (nEntitySize > psSHP->nBufSize) | |
if (psSHP->pabyRec==NULL) | |
if (psSHP->sHooks.FSeek(psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0) !=0) | |
if (nBytesRead >=8 &&nBytesRead==nEntitySize - 8) | |
else | if (nBytesRead !=nEntitySize) |
if (8+4 > nEntitySize) | |
if (bBigEndian) | |
if (psShape->nSHPType==SHPT_POLYGON||psShape->nSHPType==SHPT_ARC||psShape->nSHPType==SHPT_POLYGONZ||psShape->nSHPType==SHPT_POLYGONM||psShape->nSHPType==SHPT_ARCZ||psShape->nSHPType==SHPT_ARCM||psShape->nSHPType==SHPT_MULTIPATCH) | |
return (psShape) | |
const char SHPAPI_CALL1 * | SHPTypeName (int nSHPType){ switch(nSHPType |
const char SHPAPI_CALL1 * | SHPPartTypeName (int nPartType){ switch(nPartType |
void SHPAPI_CALL | SHPDestroyObject (SHPObject *psShape) |
int SHPAPI_CALL | SHPRewindObject (CPL_UNUSED SHPHandle hSHP, SHPObject *psObject) |
Variables | |
psObject | nSHPType = nSHPType |
psObject | nShapeId = nShapeId |
psObject | bMeasureIsUsed = FALSE |
else | |
bHasZ = FALSE | |
psObject | nVertices = nVertices |
nEntitySize = psSHP->panRecSize[hEntity]+8 | |
nBytesRead = (int)psSHP->sHooks.FRead( psSHP->pabyRec, 1, nEntitySize, psSHP->fpSHP ) | |
else | psShape = (SHPObject *) calloc(1,sizeof(SHPObject)) |
psShape | bFastModeReadObject = psSHP->bFastModeReadObject |
Definition at line 296 of file shpopen.c.
Referenced by SHPCreateLL(), and SHPWriteHeader().
#define FALSE 0 |
Definition at line 292 of file shpopen.c.
Referenced by if(), SHPCreateLL(), SHPDestroyObject(), SHPOpenLL(), SHPRestoreSHX(), SHPRewindObject(), and SHPWriteObject().
Definition at line 299 of file shpopen.c.
Referenced by SHPComputeExtents().
Definition at line 298 of file shpopen.c.
Referenced by SHPComputeExtents().
#define TRUE 1 |
Definition at line 293 of file shpopen.c.
Referenced by if(), SHPCreateLL(), SHPOpenLL(), SHPRestoreSHX(), and SHPWriteObject().
if | ( | nSHPType | = = SHPT_ARCM || nSHPType == SHPT_POINTM || nSHPType == SHPT_POLYGONM || nSHPType == SHPT_MULTIPOINTM | ) |
Definition at line 1403 of file shpopen.c.
References FALSE, SHPT_ARCZ, SHPT_MULTIPATCH, SHPT_MULTIPOINTZ, SHPT_POINTZ, SHPT_POLYGONZ, and TRUE.
if | ( | nVertices | , |
0 | |||
) |
Definition at line 1463 of file shpopen.c.
References tagSHPObject::bMeasureIsUsed, NULL, nVertices, tagSHPObject::padfM, tagSHPObject::padfX, tagSHPObject::padfY, tagSHPObject::padfZ, and TRUE.
if | ( | psSHP-> | panRecOffset[hEntity] = = 0 && psSHP->fpSHX != NULL | ) |
Definition at line 1998 of file shpopen.c.
References SAHooks::Error, SHPInfo::fpSHX, SAHooks::FRead, SAHooks::FSeek, NULL, and SHPInfo::sHooks.
if | ( | nEntitySize | , |
psSHP-> | nBufSize | ||
) |
Definition at line 2044 of file shpopen.c.
References SHPInfo::fpSHP, SAHooks::FSeek, SAHooks::FTell, nEntitySize, SHPInfo::nFileSize, SHPInfo::panRecOffset, and SHPInfo::sHooks.
if | ( | psSHP->sHooks.FSeek(psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0) ! | = 0 | ) |
Definition at line 2106 of file shpopen.c.
References SAHooks::Error, NULL, SHPInfo::panRecOffset, and SHPInfo::sHooks.
if | ( | nBytesRead >=8 && | nBytesRead = = nEntitySize - 8 | ) |
Definition at line 2129 of file shpopen.c.
References SHPInfo::pabyRec.
else if | ( | nBytesRead ! | = nEntitySize | ) |
Definition at line 2148 of file shpopen.c.
References SAHooks::Error, NULL, SHPInfo::panRecOffset, and SHPInfo::sHooks.
if | ( | 8+ | 4, |
nEntitySize | |||
) |
Definition at line 2163 of file shpopen.c.
References SAHooks::Error, NULL, SHPInfo::pabyRec, and SHPInfo::sHooks.
else if | ( | psShape-> | nSHPType = = SHPT_POLYGON || psShape->nSHPType == SHPT_ARC || psShape->nSHPType == SHPT_POLYGONZ || psShape->nSHPType == SHPT_POLYGONM || psShape->nSHPType == SHPT_ARCZ || psShape->nSHPType == SHPT_ARCM || psShape->nSHPType == SHPT_MULTIPATCH | ) |
Definition at line 2200 of file shpopen.c.
References tagSHPObject::dfXMax, tagSHPObject::dfXMin, tagSHPObject::dfYMax, tagSHPObject::dfYMin, SAHooks::Error, NULL, SHPInfo::pabyRec, SHPInfo::sHooks, and SHPDestroyObject().
return | ( | psObject | ) |
return | ( | psShape | ) |
void SHPAPI_CALL SHPClose | ( | SHPHandle | psSHP | ) |
Definition at line 1073 of file shpopen.c.
References SHPInfo::bUpdated, SAHooks::FClose, SHPInfo::fpSHP, SHPInfo::fpSHX, free(), NULL, SHPInfo::pabyObjectBuf, SHPInfo::pabyRec, SHPInfo::panRecOffset, SHPInfo::panRecSize, SHPInfo::psCachedObject, SHPInfo::sHooks, and SHPWriteHeader().
void SHPAPI_CALL SHPComputeExtents | ( | SHPObject * | psObject | ) |
Definition at line 1348 of file shpopen.c.
References bHasZ, tagSHPObject::dfMMax, tagSHPObject::dfMMin, tagSHPObject::dfXMax, tagSHPObject::dfXMin, tagSHPObject::dfYMax, tagSHPObject::dfYMin, tagSHPObject::dfZMax, tagSHPObject::dfZMin, MAX, MIN, nShapeId, nSHPType, tagSHPObject::nVertices, nVertices, tagSHPObject::padfM, tagSHPObject::padfX, tagSHPObject::padfY, tagSHPObject::padfZ, SHPAPI_CALL1, and SHPCreateObject().
SHPComputeExtents | ( | psObject | ) |
SHPHandle SHPAPI_CALL SHPCreate | ( | const char * | pszLayer, |
int | nShapeType | ||
) |
Definition at line 1173 of file shpopen.c.
References SASetupDefaultHooks(), SHPAPI_CALL, and SHPCreateLL().
SHPHandle SHPAPI_CALL SHPCreateLL | ( | const char * | pszLayer, |
int | nShapeType, | ||
SAHooks * | psHooks | ||
) |
Definition at line 1191 of file shpopen.c.
References ByteCopy, SAHooks::Error, FALSE, SAHooks::FOpen, free(), malloc(), NULL, and TRUE.
Referenced by SHPCreate().
SHPObject SHPAPI_CALL1* SHPCreateObject | ( | int | nSHPType, |
int | nShapeId, | ||
int | nParts, | ||
const int * | panPartStart, | ||
const int * | panPartType, | ||
int | nVertices, | ||
const double * | padfX, | ||
const double * | padfY, | ||
const double * | padfZ, | ||
const double * | padfM | ||
) |
Referenced by SHPComputeExtents().
SHPObject SHPAPI_CALL1* SHPCreateSimpleObject | ( | int | nSHPType, |
int | nVertices, | ||
const double * | padfX, | ||
const double * | padfY, | ||
const double * | padfZ | ||
) |
void SHPAPI_CALL SHPDestroyObject | ( | SHPObject * | psShape | ) |
Definition at line 2766 of file shpopen.c.
References tagSHPObject::bFastModeReadObject, FALSE, free(), NULL, tagSHPObject::padfM, tagSHPObject::padfX, tagSHPObject::padfY, tagSHPObject::padfZ, tagSHPObject::panPartStart, tagSHPObject::panPartType, and SHPAPI_CALL.
Referenced by if().
void SHPAPI_CALL SHPGetInfo | ( | SHPHandle | psSHP, |
int * | pnEntities, | ||
int * | pnShapeType, | ||
double * | padfMinBound, | ||
double * | padfMaxBound | ||
) |
Definition at line 1141 of file shpopen.c.
References SHPInfo::adBoundsMax, SHPInfo::adBoundsMin, SHPInfo::nRecords, SHPInfo::nShapeType, NULL, and SHPAPI_CALL.
SHPHandle SHPAPI_CALL SHPOpen | ( | const char * | pszLayer, |
const char * | pszAccess | ||
) |
Definition at line 489 of file shpopen.c.
References SASetupDefaultHooks(), SHPAPI_CALL, and SHPOpenLL().
SHPHandle SHPAPI_CALL SHPOpenLL | ( | const char * | pszLayer, |
const char * | pszAccess, | ||
SAHooks * | psHooks | ||
) |
Definition at line 507 of file shpopen.c.
References SHPInfo::bUpdated, SAHooks::Error, FALSE, SAHooks::FClose, SAHooks::FOpen, SHPInfo::fpSHP, SHPInfo::fpSHX, SAHooks::FRead, free(), malloc(), SHPInfo::nFileSize, NULL, SHPInfo::sHooks, and TRUE.
Referenced by SHPOpen(), and SHPOpenLLEx().
SHPHandle SHPAPI_CALL SHPOpenLLEx | ( | const char * | pszLayer, |
const char * | pszAccess, | ||
SAHooks * | psHooks, | ||
int | bRestoreSHX | ||
) |
Definition at line 850 of file shpopen.c.
References NULL, SHPAPI_CALL, SHPOpenLL(), and SHPRestoreSHX().
const char SHPAPI_CALL1* SHPPartTypeName | ( | int | nPartType | ) |
Definition at line 2733 of file shpopen.c.
References SHPAPI_CALL, SHPP_FIRSTRING, SHPP_INNERRING, SHPP_OUTERRING, SHPP_RING, SHPP_TRIFAN, and SHPP_TRISTRIP.
SHPObject SHPAPI_CALL1* SHPReadObject | ( | SHPHandle | psSHP, |
int | hEntity | ||
) | -> nRecords) return(NULL |
int SHPAPI_CALL SHPRestoreSHX | ( | const char * | pszLayer, |
const char * | pszAccess, | ||
SAHooks * | psHooks | ||
) |
Definition at line 874 of file shpopen.c.
References SAHooks::Error, FALSE, SAHooks::FOpen, SAHooks::FRead, free(), malloc(), NULL, and TRUE.
Referenced by SHPOpenLLEx().
int SHPAPI_CALL SHPRewindObject | ( | CPL_UNUSED SHPHandle | hSHP, |
SHPObject * | psObject | ||
) |
Definition at line 2803 of file shpopen.c.
References FALSE, tagSHPObject::nParts, tagSHPObject::nSHPType, tagSHPObject::nVertices, tagSHPObject::padfM, tagSHPObject::padfX, tagSHPObject::padfY, tagSHPObject::padfZ, tagSHPObject::panPartStart, SHPT_POLYGON, SHPT_POLYGONM, and SHPT_POLYGONZ.
void SHPAPI_CALL SHPSetFastModeReadObject | ( | SHPHandle | hSHP, |
int | bFastMode | ||
) |
Definition at line 1120 of file shpopen.c.
References assert, SHPInfo::bFastModeReadObject, NULL, SHPInfo::psCachedObject, and SHPAPI_CALL.
const char SHPAPI_CALL1* SHPTypeName | ( | int | nSHPType | ) |
Definition at line 2676 of file shpopen.c.
References SHPAPI_CALL1, SHPT_ARC, SHPT_ARCM, SHPT_ARCZ, SHPT_MULTIPATCH, SHPT_MULTIPOINT, SHPT_MULTIPOINTM, SHPT_MULTIPOINTZ, SHPT_NULL, SHPT_POINT, SHPT_POINTM, SHPT_POINTZ, SHPT_POLYGON, SHPT_POLYGONM, and SHPT_POLYGONZ.
void SHPAPI_CALL SHPWriteHeader | ( | SHPHandle | psSHP | ) |
Definition at line 359 of file shpopen.c.
References ByteCopy, SAHooks::Error, SHPInfo::fpSHX, SHPInfo::nFileSize, NULL, and SHPInfo::sHooks.
Referenced by SHPClose().
int SHPAPI_CALL SHPWriteObject | ( | SHPHandle | psSHP, |
int | nShapeId, | ||
SHPObject * | psObject | ||
) |
Definition at line 1519 of file shpopen.c.
References assert, SHPInfo::bUpdated, FALSE, SHPInfo::nMaxRecords, SHPInfo::nRecords, SHPInfo::nShapeType, tagSHPObject::nSHPType, SHPT_NULL, and TRUE.
bHasZ = FALSE |
Definition at line 1423 of file shpopen.c.
Referenced by SHPComputeExtents().
else |
nBytesRead = (int)psSHP->sHooks.FRead( psSHP->pabyRec, 1, nEntitySize, psSHP->fpSHP ) |
nEntitySize = psSHP->panRecSize[hEntity]+8 |
psShape nShapeId = nShapeId |
Definition at line 1397 of file shpopen.c.
Referenced by SHPComputeExtents().
psShape nSHPType = nSHPType |
Definition at line 1396 of file shpopen.c.
Referenced by SHPComputeExtents().
psObject nVertices = nVertices |
Definition at line 1488 of file shpopen.c.
Referenced by if(), and SHPComputeExtents().