shpopen.c File Reference

#include "shapefil.h"
#include <math.h>
#include <limits.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define ByteCopy(a, b, c)   memcpy( b, a, c )
#define FALSE   0
#define MAX(a, b)   ((a>b) ? a : b)
#define MIN(a, b)   ((a<b) ? a : b)
#define TRUE   1

Typedefs

typedef int int32
typedef unsigned char uchar

Functions

static void _SHPSetBounds (uchar *pabyRec, SHPObject *psShape)
 fread (psSHP->pabyRec, psSHP->panRecSize[hEntity]+8, 1, psSHP->fpSHP)
 fseek (psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0)
else if (psShape->nSHPType==SHPT_MULTIPOINT||psShape->nSHPType==SHPT_MULTIPOINTM||psShape->nSHPType==SHPT_MULTIPOINTZ)
 if (bBigEndian)
 if (psSHP->panRecSize[hEntity]+8 > psSHP->nBufSize)
 if (nSHPType==SHPT_ARCM||nSHPType==SHPT_POINTM||nSHPType==SHPT_POLYGONM||nSHPType==SHPT_MULTIPOINTM)
 memcpy (&psShape->nSHPType, psSHP->pabyRec+8, 4)
 return (psShape)
 return (psObject)
static void * SfRealloc (void *pMem, int nNewSize)
void SHPAPI_CALL SHPClose (SHPHandle psSHP)
 SHPComputeExtents (psObject)
void SHPAPI_CALL SHPComputeExtents (SHPObject *psObject)
SHPHandle SHPAPI_CALL SHPCreate (const char *pszLayer, int nShapeType)
SHPObject SHPAPI_CALL1 * SHPCreateObject (int nSHPType, int nShapeId, int nParts, int *panPartStart, int *panPartType, int nVertices, double *padfX, double *padfY, double *padfZ, double *padfM){SHPObject *psObject;inti, bHasM, bHasZ;psObject=(SHPObject *) calloc(1, sizeof(SHPObject)
SHPObject SHPAPI_CALL1 * SHPCreateSimpleObject (int nSHPType, int nVertices, double *padfX, double *padfY, double *padfZ){return(SHPCreateObject(nSHPType,-1, 0, NULL, NULL, nVertices, padfX, padfY, padfZ, NULL)
void SHPAPI_CALL SHPDestroyObject (SHPObject *psShape)
void SHPAPI_CALL SHPGetInfo (SHPHandle psSHP, int *pnEntities, int *pnShapeType, double *padfMinBound, double *padfMaxBound)
SHPHandle SHPAPI_CALL SHPOpen (const char *pszLayer, const char *pszAccess)
const char SHPAPI_CALL1 * SHPPartTypeName (int nPartType){switch(nPartType
SHPObject SHPAPI_CALL1 * SHPReadObject (SHPHandle psSHP, int hEntity){SHPObject *psShape;if(hEntity< 0||hEntity >=psSHP->nRecords) return(NULL
int SHPAPI_CALL SHPRewindObject (SHPHandle hSHP, SHPObject *psObject)
const char SHPAPI_CALL1 * SHPTypeName (int nSHPType){switch(nSHPType
static void SHPWriteHeader (SHPHandle psSHP)
int SHPAPI_CALL SHPWriteObject (SHPHandle psSHP, int nShapeId, SHPObject *psObject)
static void SwapWord (int length, void *wordP)

Variables

static int bBigEndian
psShape nShapeId = hEntity
psObject nShapeId = nShapeId
psObject nSHPType = nSHPType
 psShape = (SHPObject *) calloc(1,sizeof(SHPObject))


Define Documentation

#define ByteCopy ( a,
b,
c   )     memcpy( b, a, c )

Definition at line 188 of file shpopen.c.

Referenced by _SHPSetBounds(), SHPCreate(), SHPWriteHeader(), and SHPWriteObject().

#define FALSE   0

Definition at line 184 of file shpopen.c.

#define MAX ( a,
b   )     ((a>b) ? a : b)

Examples:
TePDIMMIOMatching_test.cpp, and TePDIOFMatching_test.cpp.

Definition at line 191 of file shpopen.c.

Referenced by TePDIMMIOMatching::bicubicResampleMatrix(), TePDIVenturaFusion::CheckParameters(), TePDIMallatWavelets::CheckParameters(), TePDIGarguetFusion::CheckParameters(), TeSAM::TeRTree< DATATYPE, MAXNODES, MINNODES >::combineRect(), deletePointedObjects(), TePDIGarguetFusion::findBestDecimLevel(), TePDIParallelSegmenter::flushBlock(), TeDatabase::getMBRGeom(), TeQtTextEdit::getRect(), TeQtGLWidget::getValues(), TePostgreSQL::insertLine(), TeOCIOracle::insertLine(), TeMySQL::insertLine(), TeFirebird::insertLine(), TeSqlServer::insertLine(), TeOracle::insertLine(), TeAdo::insertLine(), TeMySQL::insertLineSet(), TeSqlServer::insertLineSet(), TeOracle::insertLineSet(), TeAdo::insertLineSet(), TePostgreSQL::insertPolygon(), TeOCIOracle::insertPolygon(), TeMySQL::insertPolygon(), TeFirebird::insertPolygon(), TeSqlServer::insertPolygon(), TeOracle::insertPolygon(), TeAdo::insertPolygon(), TeMySQL::insertPolygonSet(), TeSqlServer::insertPolygonSet(), TeAdo::insertPolygonSet(), TePDIUtils::resampleRasterByLinsCols(), TeRasterMemManager::reset(), TePDIMatrix< ElementType >::Reset(), RGBtoHSV(), rotateRasterClockWize(), TePDIColorTransform::RunIhs2Rgb(), TePDITPMosaic::RunImplementation(), TePDISensorSimulator::RunImplementation(), TePDIRegister::RunImplementation(), TePDIRaster2Vector::RunImplementation(), TePDIParallelSegmenter::RunImplementation(), TePDIIHSFusion::RunImplementation(), TePDIGeoMosaic::RunImplementation(), TePDIArithmetic::RunImplementation(), TePDIWaveletAtrous::RunImplementation_recompose(), TeAbstractTheme::setStatusForItemsToggled(), SHPComputeExtents(), SHPOpen(), SHPWriteObject(), TeCalculateStatistics(), TeINTERSECTOR2::TeCCW(), TeGroupByEqualStep(), TeGroupByStdDev(), TeINTERSECTOR2::TeIndexPolygonSet(), TeRasterRemap::TeInterpolateIn(), TeINTERSECTOR2::TeIntersection(), TeIntersection(), TeINTERSECTOR2::TeIntersects(), TeINTERSECTOR2::TeIsSimple(), TeMinimumDistance(), TeNearest(), TeRasterRemap::TeOptimizedInterpolateIn(), TePDIUtils::TeSegSetIntersection(), TeUnion(), TePostgreSQL::updateLine(), TeOCIOracle::updateLine(), TeMySQL::updateLine(), TeFirebird::updateLine(), TeAdo::updateLine(), TePostgreSQL::updatePolygon(), TeOCIOracle::updatePolygon(), TeMySQL::updatePolygon(), TeFirebird::updatePolygon(), and TeAdo::updatePolygon().

#define MIN ( a,
b   )     ((a<b) ? a : b)

Examples:
TePDIMatrix_test.cpp, TePDIMMIOMatching_test.cpp, and TePDIOFMatching_test.cpp.

Definition at line 190 of file shpopen.c.

Referenced by TePDIMallatWavelets::AgregateSubBands(), automem_test(), AutoMemPol_test(), backupOnePage(), TePDIMMIOMatching::bicubicResampleMatrix(), TePDIMallatWavelets::CheckParameters(), TeSAM::TeRTree< DATATYPE, MAXNODES, MINNODES >::combineRect(), DecoderSmartMem_test(), deletePointedObjects(), TePDIMMIOMatching::extractLocalMaximas(), TePDIGarguetFusion::findBestDecimLevel(), TePDIVenturaFusion::findBestDecimLevels(), TePDIParallelSegmenter::flushBlock(), TePDIWiSpeRFusion::fractions(), TePDIMMIOMatching::generateMaximasRaster(), TePDIMatrixFunctions::GetCorrelation(), TeMappedMemory::getLastErrorStr(), TePDIOFMatching::getMaximaPoints(), TeDatabase::getMBRGeom(), TeQtTextEdit::getRect(), TeQtGLWidget::getValues(), TeQtTextEdit::isHotPoint(), TeQtTextEdit::located(), TePDIMMIOMatching::matrix2Tiff(), memjrnlRead(), memjrnlWrite(), RAMMemPol_test(), TeGeometricTransformation::ransacRemotion(), raster2Tiff(), TeAddressLocator::refineFoundedLocationsByNumberNeighboor(), TeAddressLocator::refineFoundedLocationsByNumberZipCode(), TePDIUtils::resampleRasterByLinsCols(), TeRasterMemManager::reset(), TePDIMatrix< ElementType >::Reset(), TePDIIHSWaveletFusion::rgb2ihs(), RGBtoHSV(), rotateRasterClockWize(), TePDIColorTransform::RunIhs2Rgb(), TePDIVenturaFusion::RunImplementation(), TePDITPMosaic::RunImplementation(), TePDIRegister::RunImplementation(), TePDIParallelSegmenter::RunImplementation(), TePDIOFMatching::RunImplementation(), TePDIMMIOMatching::RunImplementation(), TePDIIHSFusion::RunImplementation(), TePDIGeoMosaic::RunImplementation(), TePDIArithmetic::RunImplementation(), TePDIWaveletAtrous::RunImplementation_recompose(), TePDIColorTransform::RunRgb2Ihs(), SHPComputeExtents(), SHPWriteObject(), sqlite3_backup_step(), TeCalculateStatistics(), TeINTERSECTOR2::TeCCW(), TeGroupByEqualStep(), TeGroupByStdDev(), TeINTERSECTOR2::TeIndexPolygonSet(), TeRasterRemap::TeInterpolateIn(), TeINTERSECTOR2::TeIntersection(), TeIntersection(), TeINTERSECTOR2::TeIntersects(), TeINTERSECTOR2::TeIsSimple(), TeMinimumDistance(), TeNearest(), TePDIUtils::TeSegSetIntersection(), and TeUnion().

#define TRUE   1

Definition at line 185 of file shpopen.c.


Typedef Documentation

typedef int int32

Definition at line 180 of file shpopen.c.

typedef unsigned char uchar

Definition at line 175 of file shpopen.c.


Function Documentation

static void _SHPSetBounds ( uchar pabyRec,
SHPObject psShape 
) [static]

Definition at line 727 of file shpopen.c.

References bBigEndian, ByteCopy, SHPObject::dfXMax, SHPObject::dfXMin, SHPObject::dfYMax, SHPObject::dfYMin, and SwapWord().

Referenced by SHPWriteObject().

00729 {
00730     ByteCopy( &(psShape->dfXMin), pabyRec +  0, 8 );
00731     ByteCopy( &(psShape->dfYMin), pabyRec +  8, 8 );
00732     ByteCopy( &(psShape->dfXMax), pabyRec + 16, 8 );
00733     ByteCopy( &(psShape->dfYMax), pabyRec + 24, 8 );
00734 
00735     if( bBigEndian )
00736     {
00737         SwapWord( 8, pabyRec + 0 );
00738         SwapWord( 8, pabyRec + 8 );
00739         SwapWord( 8, pabyRec + 16 );
00740         SwapWord( 8, pabyRec + 24 );
00741     }
00742 }

fread ( psSHP->  pabyRec,
psSHP->panRecSize+  8[hEntity],
,
psSHP->  fpSHP 
)

Referenced by DBFClose(), DBFOpen(), DBFReadAttribute(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), DBFWriteTuple(), TePDIMatrix< ElementType >::getScanLine(), TeRasterMemManager::getTilePointer(), if(), TeDatabase::insertBlob(), TeGTM::readGTM(), TeGTMGridDatum::readGTMGridDatum(), TeGTMHeader::readGTMHeader(), TeGTMInformationImages::readGTMInformationImages(), TeGTMLayers::readGTMLayers(), TeGTMRoutes::readGTMRoutes(), TeGTMTrackLogs::readGTMTrackLogs(), TeGTMTrackLogStyles::readGTMTrackLogStyles(), TeGTMUserIcons::readGTMUserIcons(), TeGTMWaypoints::readGTMWaypoints(), TeGTMWaypointsStyles::readGTMWaypointsStyles(), and SHPOpen().

fseek ( psSHP->  fpSHP,
psSHP->  panRecOffset[hEntity],
 
)

Referenced by TeRasterMemManager::createNewDiskFile(), TePDIMatrix< ElementType >::createNewDiskFile(), DBFClose(), DBFFlushRecord(), DBFOpen(), DBFReadAttribute(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), DBFWriteHeader(), DBFWriteTuple(), TePDIMatrix< ElementType >::getScanLine(), TeRasterMemManager::getTilePointer(), if(), TeStdFile::rewind(), SHPWriteHeader(), SHPWriteObject(), and TeGetFileSize().

else if ( psShape->  nSHPType = = SHPT_MULTIPOINT || psShape->nSHPType == SHPT_MULTIPOINTM || psShape->nSHPType == SHPT_MULTIPOINTZ  ) 

Definition at line 1457 of file shpopen.c.

References bBigEndian, SHPObject::dfMMax, SHPObject::dfMMin, SHPObject::dfXMax, SHPObject::dfXMin, SHPObject::dfYMax, SHPObject::dfYMin, SHPObject::dfZMax, SHPObject::dfZMin, memcpy(), SHPObject::nSHPType, SHPObject::nVertices, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, SHPT_MULTIPOINTZ, and SwapWord().

01460     {
01461         int32           nPoints;
01462         int             i, nOffset;
01463 
01464         memcpy( &nPoints, psSHP->pabyRec + 44, 4 );
01465         if( bBigEndian ) SwapWord( 4, &nPoints );
01466 
01467         psShape->nVertices = nPoints;
01468         psShape->padfX = (double *) calloc(nPoints,sizeof(double));
01469         psShape->padfY = (double *) calloc(nPoints,sizeof(double));
01470         psShape->padfZ = (double *) calloc(nPoints,sizeof(double));
01471         psShape->padfM = (double *) calloc(nPoints,sizeof(double));
01472 
01473         for( i = 0; i < nPoints; i++ )
01474         {
01475             memcpy(psShape->padfX+i, psSHP->pabyRec + 48 + 16 * i, 8 );
01476             memcpy(psShape->padfY+i, psSHP->pabyRec + 48 + 16 * i + 8, 8 );
01477 
01478             if( bBigEndian ) SwapWord( 8, psShape->padfX + i );
01479             if( bBigEndian ) SwapWord( 8, psShape->padfY + i );
01480         }
01481 
01482         nOffset = 48 + 16*nPoints;
01483         
01484 /* -------------------------------------------------------------------- */
01485 /*      Get the X/Y bounds.                                             */
01486 /* -------------------------------------------------------------------- */
01487         memcpy( &(psShape->dfXMin), psSHP->pabyRec + 8 +  4, 8 );
01488         memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
01489         memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
01490         memcpy( &(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
01491 
01492         if( bBigEndian ) SwapWord( 8, &(psShape->dfXMin) );
01493         if( bBigEndian ) SwapWord( 8, &(psShape->dfYMin) );
01494         if( bBigEndian ) SwapWord( 8, &(psShape->dfXMax) );
01495         if( bBigEndian ) SwapWord( 8, &(psShape->dfYMax) );
01496 
01497 /* -------------------------------------------------------------------- */
01498 /*      If we have a Z coordinate, collect that now.                    */
01499 /* -------------------------------------------------------------------- */
01500         if( psShape->nSHPType == SHPT_MULTIPOINTZ )
01501         {
01502             memcpy( &(psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
01503             memcpy( &(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
01504             
01505             if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );
01506             if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );
01507             
01508             for( i = 0; i < nPoints; i++ )
01509             {
01510                 memcpy( psShape->padfZ + i,
01511                         psSHP->pabyRec + nOffset + 16 + i*8, 8 );
01512                 if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );
01513             }
01514 
01515             nOffset += 16 + 8*nPoints;
01516         }
01517 
01518 /* -------------------------------------------------------------------- */
01519 /*      If we have a M measure value, then read it now.  We assume      */
01520 /*      that the measure can be present for any shape if the size is    */
01521 /*      big enough, but really it will only occur for the Z shapes      */
01522 /*      (options), and the M shapes.                                    */
01523 /* -------------------------------------------------------------------- */
01524         if( psSHP->panRecSize[hEntity]+8 >= nOffset + 16 + 8*nPoints )
01525         {
01526             memcpy( &(psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
01527             memcpy( &(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
01528             
01529             if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );
01530             if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );
01531             
01532             for( i = 0; i < nPoints; i++ )
01533             {
01534                 memcpy( psShape->padfM + i,
01535                         psSHP->pabyRec + nOffset + 16 + i*8, 8 );
01536                 if( bBigEndian ) SwapWord( 8, psShape->padfM + i );
01537             }
01538         }
01539     }

if ( bBigEndian   ) 

Definition at line 1312 of file shpopen.c.

01323     {
01324         int32           nPoints, nParts;
01325         int             i, nOffset;
01326 
01327 /* -------------------------------------------------------------------- */
01328 /*      Get the X/Y bounds.                                             */
01329 /* -------------------------------------------------------------------- */
01330         memcpy( &(psShape->dfXMin), psSHP->pabyRec + 8 +  4, 8 );
01331         memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
01332         memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
01333         memcpy( &(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
01334 
01335         if( bBigEndian ) SwapWord( 8, &(psShape->dfXMin) );
01336         if( bBigEndian ) SwapWord( 8, &(psShape->dfYMin) );
01337         if( bBigEndian ) SwapWord( 8, &(psShape->dfXMax) );
01338         if( bBigEndian ) SwapWord( 8, &(psShape->dfYMax) );
01339 
01340 /* -------------------------------------------------------------------- */
01341 /*      Extract part/point count, and build vertex and part arrays      */
01342 /*      to proper size.                                                 */
01343 /* -------------------------------------------------------------------- */
01344         memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );
01345         memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );
01346 
01347         if( bBigEndian ) SwapWord( 4, &nPoints );
01348         if( bBigEndian ) SwapWord( 4, &nParts );
01349 
01350         psShape->nVertices = nPoints;
01351         psShape->padfX = (double *) calloc(nPoints,sizeof(double));
01352         psShape->padfY = (double *) calloc(nPoints,sizeof(double));
01353         psShape->padfZ = (double *) calloc(nPoints,sizeof(double));
01354         psShape->padfM = (double *) calloc(nPoints,sizeof(double));
01355 
01356         psShape->nParts = nParts;
01357         psShape->panPartStart = (int *) calloc(nParts,sizeof(int));
01358         psShape->panPartType = (int *) calloc(nParts,sizeof(int));
01359 
01360         for( i = 0; i < nParts; i++ )
01361             psShape->panPartType[i] = SHPP_RING;
01362 
01363 /* -------------------------------------------------------------------- */
01364 /*      Copy out the part array from the record.                        */
01365 /* -------------------------------------------------------------------- */
01366         memcpy( psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );
01367         for( i = 0; i < nParts; i++ )
01368         {
01369             if( bBigEndian ) SwapWord( 4, psShape->panPartStart+i );
01370         }
01371 
01372         nOffset = 44 + 8 + 4*nParts;
01373 
01374 /* -------------------------------------------------------------------- */
01375 /*      If this is a multipatch, we will also have parts types.         */
01376 /* -------------------------------------------------------------------- */
01377         if( psShape->nSHPType == SHPT_MULTIPATCH )
01378         {
01379             memcpy( psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );
01380             for( i = 0; i < nParts; i++ )
01381             {
01382                 if( bBigEndian ) SwapWord( 4, psShape->panPartType+i );
01383             }
01384 
01385             nOffset += 4*nParts;
01386         }
01387         
01388 /* -------------------------------------------------------------------- */
01389 /*      Copy out the vertices from the record.                          */
01390 /* -------------------------------------------------------------------- */
01391         for( i = 0; i < nPoints; i++ )
01392         {
01393             memcpy(psShape->padfX + i,
01394                    psSHP->pabyRec + nOffset + i * 16,
01395                    8 );
01396 
01397             memcpy(psShape->padfY + i,
01398                    psSHP->pabyRec + nOffset + i * 16 + 8,
01399                    8 );
01400 
01401             if( bBigEndian ) SwapWord( 8, psShape->padfX + i );
01402             if( bBigEndian ) SwapWord( 8, psShape->padfY + i );
01403         }
01404 
01405         nOffset += 16*nPoints;
01406         
01407 /* -------------------------------------------------------------------- */
01408 /*      If we have a Z coordinate, collect that now.                    */
01409 /* -------------------------------------------------------------------- */
01410         if( psShape->nSHPType == SHPT_POLYGONZ
01411             || psShape->nSHPType == SHPT_ARCZ
01412             || psShape->nSHPType == SHPT_MULTIPATCH )
01413         {
01414             memcpy( &(psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
01415             memcpy( &(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
01416             
01417             if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );
01418             if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );
01419             
01420             for( i = 0; i < nPoints; i++ )
01421             {
01422                 memcpy( psShape->padfZ + i,
01423                         psSHP->pabyRec + nOffset + 16 + i*8, 8 );
01424                 if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );
01425             }
01426 
01427             nOffset += 16 + 8*nPoints;
01428         }
01429 
01430 /* -------------------------------------------------------------------- */
01431 /*      If we have a M measure value, then read it now.  We assume      */
01432 /*      that the measure can be present for any shape if the size is    */
01433 /*      big enough, but really it will only occur for the Z shapes      */
01434 /*      (options), and the M shapes.                                    */
01435 /* -------------------------------------------------------------------- */
01436         if( psSHP->panRecSize[hEntity]+8 >= nOffset + 16 + 8*nPoints )
01437         {
01438             memcpy( &(psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
01439             memcpy( &(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
01440             
01441             if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );
01442             if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );
01443             
01444             for( i = 0; i < nPoints; i++ )
01445             {
01446                 memcpy( psShape->padfM + i,
01447                         psSHP->pabyRec + nOffset + 16 + i*8, 8 );
01448                 if( bBigEndian ) SwapWord( 8, psShape->padfM + i );
01449             }
01450         }
01451         
01452     }

if ( psSHP->panRecSize+  8[hEntity],
psSHP->  nBufSize 
)

Definition at line 1293 of file shpopen.c.

References SfRealloc().

01294     {
01295         psSHP->nBufSize = psSHP->panRecSize[hEntity]+8;
01296         psSHP->pabyRec = (uchar *) SfRealloc(psSHP->pabyRec,psSHP->nBufSize);
01297     }

else if ( nSHPType  = = SHPT_ARCM || nSHPType == SHPT_POINTM || nSHPType == SHPT_POLYGONM || nSHPType == SHPT_MULTIPOINTM  ) 

Definition at line 806 of file shpopen.c.

References FALSE, and TRUE.

00810     {
00811         bHasM = TRUE;
00812         bHasZ = FALSE;
00813     }

memcpy ( &psShape->  nSHPType,
psSHP->pabyRec 8,
 
)

return ( psShape   ) 

return ( psObject   ) 

static void* SfRealloc ( void *  pMem,
int  nNewSize 
) [static]

Definition at line 224 of file shpopen.c.

References NULL.

00226 {
00227     if( pMem == NULL )
00228         return( (void *) malloc(nNewSize) );
00229     else
00230         return( (void *) realloc(pMem,nNewSize) );
00231 }

void SHPAPI_CALL SHPClose ( SHPHandle  psSHP  ) 

Definition at line 556 of file shpopen.c.

References SHPInfo::bUpdated, SHPInfo::fpSHP, SHPInfo::fpSHX, NULL, SHPInfo::pabyRec, SHPInfo::panRecOffset, SHPInfo::panRecSize, and SHPWriteHeader().

00558 {
00559 /* -------------------------------------------------------------------- */
00560 /*      Update the header if we have modified anything.                 */
00561 /* -------------------------------------------------------------------- */
00562     if( psSHP->bUpdated )
00563     {
00564         SHPWriteHeader( psSHP );
00565     }
00566 
00567 /* -------------------------------------------------------------------- */
00568 /*      Free all resources, and close files.                            */
00569 /* -------------------------------------------------------------------- */
00570     free( psSHP->panRecOffset );
00571     free( psSHP->panRecSize );
00572 
00573     fclose( psSHP->fpSHX );
00574     fclose( psSHP->fpSHP );
00575 
00576     if( psSHP->pabyRec != NULL )
00577     {
00578         free( psSHP->pabyRec );
00579     }
00580     
00581     free( psSHP );
00582 }

SHPComputeExtents ( psObject   ) 

void SHPAPI_CALL SHPComputeExtents ( SHPObject psObject  ) 

Definition at line 752 of file shpopen.c.

References SHPObject::dfMMax, SHPObject::dfMMin, SHPObject::dfXMax, SHPObject::dfXMin, SHPObject::dfYMax, SHPObject::dfYMin, SHPObject::dfZMax, SHPObject::dfZMin, MAX, MIN, SHPObject::nVertices, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, and SHPObject::padfZ.

00754 {
00755     int         i;
00756     
00757 /* -------------------------------------------------------------------- */
00758 /*      Build extents for this object.                                  */
00759 /* -------------------------------------------------------------------- */
00760     if( psObject->nVertices > 0 )
00761     {
00762         psObject->dfXMin = psObject->dfXMax = psObject->padfX[0];
00763         psObject->dfYMin = psObject->dfYMax = psObject->padfY[0];
00764         psObject->dfZMin = psObject->dfZMax = psObject->padfZ[0];
00765         psObject->dfMMin = psObject->dfMMax = psObject->padfM[0];
00766     }
00767     
00768     for( i = 0; i < psObject->nVertices; i++ )
00769     {
00770         psObject->dfXMin = MIN(psObject->dfXMin, psObject->padfX[i]);
00771         psObject->dfYMin = MIN(psObject->dfYMin, psObject->padfY[i]);
00772         psObject->dfZMin = MIN(psObject->dfZMin, psObject->padfZ[i]);
00773         psObject->dfMMin = MIN(psObject->dfMMin, psObject->padfM[i]);
00774 
00775         psObject->dfXMax = MAX(psObject->dfXMax, psObject->padfX[i]);
00776         psObject->dfYMax = MAX(psObject->dfYMax, psObject->padfY[i]);
00777         psObject->dfZMax = MAX(psObject->dfZMax, psObject->padfZ[i]);
00778         psObject->dfMMax = MAX(psObject->dfMMax, psObject->padfM[i]);
00779     }
00780 }

SHPHandle SHPAPI_CALL SHPCreate ( const char *  pszLayer,
int  nShapeType 
)

Definition at line 620 of file shpopen.c.

References bBigEndian, ByteCopy, FALSE, NULL, SHPOpen(), SwapWord(), and TRUE.

00622 {
00623     char        *pszBasename, *pszFullname;
00624     int         i;
00625     FILE        *fpSHP, *fpSHX;
00626     uchar       abyHeader[100];
00627     int32       i32;
00628     double      dValue;
00629     
00630 /* -------------------------------------------------------------------- */
00631 /*      Establish the byte order on this system.                        */
00632 /* -------------------------------------------------------------------- */
00633     i = 1;
00634     if( *((uchar *) &i) == 1 )
00635         bBigEndian = FALSE;
00636     else
00637         bBigEndian = TRUE;
00638 
00639 /* -------------------------------------------------------------------- */
00640 /*      Compute the base (layer) name.  If there is any extension       */
00641 /*      on the passed in filename we will strip it off.                 */
00642 /* -------------------------------------------------------------------- */
00643     pszBasename = (char *) malloc(strlen(pszLayer)+5);
00644     strcpy( pszBasename, pszLayer );
00645     for( i = strlen(pszBasename)-1; 
00646          i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
00647                && pszBasename[i] != '\\';
00648          i-- ) {}
00649 
00650     if( pszBasename[i] == '.' )
00651         pszBasename[i] = '\0';
00652 
00653 /* -------------------------------------------------------------------- */
00654 /*      Open the two files so we can write their headers.               */
00655 /* -------------------------------------------------------------------- */
00656     pszFullname = (char *) malloc(strlen(pszBasename) + 5);
00657     sprintf( pszFullname, "%s.shp", pszBasename );
00658     fpSHP = fopen(pszFullname, "wb" );
00659     if( fpSHP == NULL )
00660         return( NULL );
00661 
00662     sprintf( pszFullname, "%s.shx", pszBasename );
00663     fpSHX = fopen(pszFullname, "wb" );
00664     if( fpSHX == NULL )
00665         return( NULL );
00666 
00667     free( pszFullname );
00668     free( pszBasename );
00669 
00670 /* -------------------------------------------------------------------- */
00671 /*      Prepare header block for .shp file.                             */
00672 /* -------------------------------------------------------------------- */
00673     for( i = 0; i < 100; i++ )
00674       abyHeader[i] = 0;
00675 
00676     abyHeader[2] = 0x27;                                /* magic cookie */
00677     abyHeader[3] = 0x0a;
00678 
00679     i32 = 50;                                           /* file size */
00680     ByteCopy( &i32, abyHeader+24, 4 );
00681     if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
00682     
00683     i32 = 1000;                                         /* version */
00684     ByteCopy( &i32, abyHeader+28, 4 );
00685     if( bBigEndian ) SwapWord( 4, abyHeader+28 );
00686     
00687     i32 = nShapeType;                                   /* shape type */
00688     ByteCopy( &i32, abyHeader+32, 4 );
00689     if( bBigEndian ) SwapWord( 4, abyHeader+32 );
00690 
00691     dValue = 0.0;                                       /* set bounds */
00692     ByteCopy( &dValue, abyHeader+36, 8 );
00693     ByteCopy( &dValue, abyHeader+44, 8 );
00694     ByteCopy( &dValue, abyHeader+52, 8 );
00695     ByteCopy( &dValue, abyHeader+60, 8 );
00696 
00697 /* -------------------------------------------------------------------- */
00698 /*      Write .shp file header.                                         */
00699 /* -------------------------------------------------------------------- */
00700     fwrite( abyHeader, 100, 1, fpSHP );
00701 
00702 /* -------------------------------------------------------------------- */
00703 /*      Prepare, and write .shx file header.                            */
00704 /* -------------------------------------------------------------------- */
00705     i32 = 50;                                           /* file size */
00706     ByteCopy( &i32, abyHeader+24, 4 );
00707     if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
00708     
00709     fwrite( abyHeader, 100, 1, fpSHX );
00710 
00711 /* -------------------------------------------------------------------- */
00712 /*      Close the files, and then open them as regular existing files.  */
00713 /* -------------------------------------------------------------------- */
00714     fclose( fpSHP );
00715     fclose( fpSHX );
00716 
00717     return( SHPOpen( pszLayer, "r+b" ) );
00718 }

SHPObject SHPAPI_CALL1* SHPCreateObject ( int  nSHPType,
int  nShapeId,
int  nParts,
int *  panPartStart,
int *  panPartType,
int  nVertices,
double *  padfX,
double *  padfY,
double *  padfZ,
double *  padfM 
)

SHPObject SHPAPI_CALL1* SHPCreateSimpleObject ( int  nSHPType,
int  nVertices,
double *  padfX,
double *  padfY,
double *  padfZ 
)

void SHPAPI_CALL SHPDestroyObject ( SHPObject psShape  ) 

Definition at line 1697 of file shpopen.c.

References NULL, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, SHPObject::panPartStart, and SHPObject::panPartType.

01699 {
01700     if( psShape == NULL )
01701         return;
01702     
01703     if( psShape->padfX != NULL )
01704         free( psShape->padfX );
01705     if( psShape->padfY != NULL )
01706         free( psShape->padfY );
01707     if( psShape->padfZ != NULL )
01708         free( psShape->padfZ );
01709     if( psShape->padfM != NULL )
01710         free( psShape->padfM );
01711 
01712     if( psShape->panPartStart != NULL )
01713         free( psShape->panPartStart );
01714     if( psShape->panPartType != NULL )
01715         free( psShape->panPartType );
01716 
01717     free( psShape );
01718 }

void SHPAPI_CALL SHPGetInfo ( SHPHandle  psSHP,
int *  pnEntities,
int *  pnShapeType,
double *  padfMinBound,
double *  padfMaxBound 
)

Definition at line 591 of file shpopen.c.

References SHPInfo::adBoundsMax, SHPInfo::adBoundsMin, SHPInfo::nRecords, SHPInfo::nShapeType, and NULL.

00594 {
00595     int         i;
00596     
00597     if( pnEntities != NULL )
00598         *pnEntities = psSHP->nRecords;
00599 
00600     if( pnShapeType != NULL )
00601         *pnShapeType = psSHP->nShapeType;
00602 
00603     for( i = 0; i < 4; i++ )
00604     {
00605         if( padfMinBound != NULL )
00606             padfMinBound[i] = psSHP->adBoundsMin[i];
00607         if( padfMaxBound != NULL )
00608             padfMaxBound[i] = psSHP->adBoundsMax[i];
00609     }
00610 }

SHPHandle SHPAPI_CALL SHPOpen ( const char *  pszLayer,
const char *  pszAccess 
)

Definition at line 344 of file shpopen.c.

References SHPInfo::adBoundsMax, SHPInfo::adBoundsMin, bBigEndian, SHPInfo::bUpdated, FALSE, SHPInfo::fpSHP, SHPInfo::fpSHX, fread(), MAX, memcpy(), SHPInfo::nFileSize, SHPInfo::nMaxRecords, SHPInfo::nRecords, SHPInfo::nShapeType, NULL, SHPInfo::panRecOffset, SHPInfo::panRecSize, SwapWord(), and TRUE.

00346 {
00347     char                *pszFullname, *pszBasename;
00348     SHPHandle           psSHP;
00349     
00350     uchar               *pabyBuf;
00351     int                 i;
00352     double              dValue;
00353     
00354 /* -------------------------------------------------------------------- */
00355 /*      Ensure the access string is one of the legal ones.  We          */
00356 /*      ensure the result string indicates binary to avoid common       */
00357 /*      problems on Windows.                                            */
00358 /* -------------------------------------------------------------------- */
00359     if( strcmp(pszAccess,"rb+") == 0 || strcmp(pszAccess,"r+b") == 0
00360         || strcmp(pszAccess,"r+") == 0 )
00361         pszAccess = "r+b";
00362     else
00363         pszAccess = "rb";
00364     
00365 /* -------------------------------------------------------------------- */
00366 /*      Establish the byte order on this machine.                       */
00367 /* -------------------------------------------------------------------- */
00368     i = 1;
00369     if( *((uchar *) &i) == 1 )
00370         bBigEndian = FALSE;
00371     else
00372         bBigEndian = TRUE;
00373 
00374 /* -------------------------------------------------------------------- */
00375 /*      Initialize the info structure.                                  */
00376 /* -------------------------------------------------------------------- */
00377     psSHP = (SHPHandle) calloc(sizeof(SHPInfo),1);
00378 
00379     psSHP->bUpdated = FALSE;
00380 
00381 /* -------------------------------------------------------------------- */
00382 /*      Compute the base (layer) name.  If there is any extension       */
00383 /*      on the passed in filename we will strip it off.                 */
00384 /* -------------------------------------------------------------------- */
00385     pszBasename = (char *) malloc(strlen(pszLayer)+5);
00386     strcpy( pszBasename, pszLayer );
00387     for( i = strlen(pszBasename)-1; 
00388          i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
00389                && pszBasename[i] != '\\';
00390          i-- ) {}
00391 
00392     if( pszBasename[i] == '.' )
00393         pszBasename[i] = '\0';
00394 
00395 /* -------------------------------------------------------------------- */
00396 /*      Open the .shp and .shx files.  Note that files pulled from      */
00397 /*      a PC to Unix with upper case filenames won't work!              */
00398 /* -------------------------------------------------------------------- */
00399     pszFullname = (char *) malloc(strlen(pszBasename) + 5);
00400     sprintf( pszFullname, "%s.shp", pszBasename );
00401     psSHP->fpSHP = fopen(pszFullname, pszAccess );
00402     if( psSHP->fpSHP == NULL )
00403     {
00404         sprintf( pszFullname, "%s.SHP", pszBasename );
00405         psSHP->fpSHP = fopen(pszFullname, pszAccess );
00406     }
00407     
00408     if( psSHP->fpSHP == NULL )
00409     {
00410         free( psSHP );
00411         free( pszBasename );
00412         free( pszFullname );
00413         return( NULL );
00414     }
00415 
00416     sprintf( pszFullname, "%s.shx", pszBasename );
00417     psSHP->fpSHX = fopen(pszFullname, pszAccess );
00418     if( psSHP->fpSHX == NULL )
00419     {
00420         sprintf( pszFullname, "%s.SHX", pszBasename );
00421         psSHP->fpSHX = fopen(pszFullname, pszAccess );
00422     }
00423     
00424     if( psSHP->fpSHX == NULL )
00425     {
00426         fclose( psSHP->fpSHP );
00427         free( psSHP );
00428         free( pszBasename );
00429         free( pszFullname );
00430         return( NULL );
00431     }
00432 
00433     free( pszFullname );
00434     free( pszBasename );
00435 
00436 /* -------------------------------------------------------------------- */
00437 /*  Read the file size from the SHP file.                               */
00438 /* -------------------------------------------------------------------- */
00439     pabyBuf = (uchar *) malloc(100);
00440     fread( pabyBuf, 100, 1, psSHP->fpSHP );
00441 
00442     psSHP->nFileSize = (pabyBuf[24] * 256 * 256 * 256
00443                         + pabyBuf[25] * 256 * 256
00444                         + pabyBuf[26] * 256
00445                         + pabyBuf[27]) * 2;
00446 
00447 /* -------------------------------------------------------------------- */
00448 /*  Read SHX file Header info                                           */
00449 /* -------------------------------------------------------------------- */
00450     fread( pabyBuf, 100, 1, psSHP->fpSHX );
00451 
00452     if( pabyBuf[0] != 0 
00453         || pabyBuf[1] != 0 
00454         || pabyBuf[2] != 0x27 
00455         || (pabyBuf[3] != 0x0a && pabyBuf[3] != 0x0d) )
00456     {
00457         fclose( psSHP->fpSHP );
00458         fclose( psSHP->fpSHX );
00459         free( psSHP );
00460 
00461         return( NULL );
00462     }
00463 
00464     psSHP->nRecords = pabyBuf[27] + pabyBuf[26] * 256
00465       + pabyBuf[25] * 256 * 256 + pabyBuf[24] * 256 * 256 * 256;
00466     psSHP->nRecords = (psSHP->nRecords*2 - 100) / 8;
00467 
00468     psSHP->nShapeType = pabyBuf[32];
00469 
00470     if( psSHP->nRecords < 0 || psSHP->nRecords > 256000000 )
00471     {
00472         /* this header appears to be corrupt.  Give up. */
00473         fclose( psSHP->fpSHP );
00474         fclose( psSHP->fpSHX );
00475         free( psSHP );
00476 
00477         return( NULL );
00478     }
00479 
00480 /* -------------------------------------------------------------------- */
00481 /*      Read the bounds.                                                */
00482 /* -------------------------------------------------------------------- */
00483     if( bBigEndian ) SwapWord( 8, pabyBuf+36 );
00484     memcpy( &dValue, pabyBuf+36, 8 );
00485     psSHP->adBoundsMin[0] = dValue;
00486 
00487     if( bBigEndian ) SwapWord( 8, pabyBuf+44 );
00488     memcpy( &dValue, pabyBuf+44, 8 );
00489     psSHP->adBoundsMin[1] = dValue;
00490 
00491     if( bBigEndian ) SwapWord( 8, pabyBuf+52 );
00492     memcpy( &dValue, pabyBuf+52, 8 );
00493     psSHP->adBoundsMax[0] = dValue;
00494 
00495     if( bBigEndian ) SwapWord( 8, pabyBuf+60 );
00496     memcpy( &dValue, pabyBuf+60, 8 );
00497     psSHP->adBoundsMax[1] = dValue;
00498 
00499     if( bBigEndian ) SwapWord( 8, pabyBuf+68 );         /* z */
00500     memcpy( &dValue, pabyBuf+68, 8 );
00501     psSHP->adBoundsMin[2] = dValue;
00502     
00503     if( bBigEndian ) SwapWord( 8, pabyBuf+76 );
00504     memcpy( &dValue, pabyBuf+76, 8 );
00505     psSHP->adBoundsMax[2] = dValue;
00506     
00507     if( bBigEndian ) SwapWord( 8, pabyBuf+84 );         /* z */
00508     memcpy( &dValue, pabyBuf+84, 8 );
00509     psSHP->adBoundsMin[3] = dValue;
00510 
00511     if( bBigEndian ) SwapWord( 8, pabyBuf+92 );
00512     memcpy( &dValue, pabyBuf+92, 8 );
00513     psSHP->adBoundsMax[3] = dValue;
00514 
00515     free( pabyBuf );
00516 
00517 /* -------------------------------------------------------------------- */
00518 /*      Read the .shx file to get the offsets to each record in         */
00519 /*      the .shp file.                                                  */
00520 /* -------------------------------------------------------------------- */
00521     psSHP->nMaxRecords = psSHP->nRecords;
00522 
00523     psSHP->panRecOffset =
00524         (int *) malloc(sizeof(int) * MAX(1,psSHP->nMaxRecords) );
00525     psSHP->panRecSize =
00526         (int *) malloc(sizeof(int) * MAX(1,psSHP->nMaxRecords) );
00527 
00528     pabyBuf = (uchar *) malloc(8 * MAX(1,psSHP->nRecords) );
00529     fread( pabyBuf, 8, psSHP->nRecords, psSHP->fpSHX );
00530 
00531     for( i = 0; i < psSHP->nRecords; i++ )
00532     {
00533         int32           nOffset, nLength;
00534 
00535         memcpy( &nOffset, pabyBuf + i * 8, 4 );
00536         if( !bBigEndian ) SwapWord( 4, &nOffset );
00537 
00538         memcpy( &nLength, pabyBuf + i * 8 + 4, 4 );
00539         if( !bBigEndian ) SwapWord( 4, &nLength );
00540 
00541         psSHP->panRecOffset[i] = nOffset*2;
00542         psSHP->panRecSize[i] = nLength*2;
00543     }
00544     free( pabyBuf );
00545 
00546     return( psSHP );
00547 }

const char SHPAPI_CALL1* SHPPartTypeName (  ) 

Definition at line 1663 of file shpopen.c.

References SHPP_FIRSTRING, SHPP_INNERRING, SHPP_OUTERRING, SHPP_RING, SHPP_TRIFAN, and SHPP_TRISTRIP.

01666 {
01667     switch( nPartType )
01668     {
01669       case SHPP_TRISTRIP:
01670         return "TriangleStrip";
01671         
01672       case SHPP_TRIFAN:
01673         return "TriangleFan";
01674 
01675       case SHPP_OUTERRING:
01676         return "OuterRing";
01677 
01678       case SHPP_INNERRING:
01679         return "InnerRing";
01680 
01681       case SHPP_FIRSTRING:
01682         return "FirstRing";
01683 
01684       case SHPP_RING:
01685         return "Ring";
01686 
01687       default:
01688         return "UnknownPartType";
01689     }

SHPObject SHPAPI_CALL1* SHPReadObject ( SHPHandle  psSHP,
int  hEntity 
)

int SHPAPI_CALL SHPRewindObject ( SHPHandle  hSHP,
SHPObject psObject 
)

Definition at line 1728 of file shpopen.c.

References FALSE, SHPObject::nParts, SHPObject::nSHPType, SHPObject::nVertices, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, SHPObject::panPartStart, SHPT_POLYGON, SHPT_POLYGONM, and SHPT_POLYGONZ.

01730 {
01731     int  iOpRing, bAltered = 0;
01732 
01733 /* -------------------------------------------------------------------- */
01734 /*      Do nothing if this is not a polygon object.                     */
01735 /* -------------------------------------------------------------------- */
01736     if( psObject->nSHPType != SHPT_POLYGON
01737         && psObject->nSHPType != SHPT_POLYGONZ
01738         && psObject->nSHPType != SHPT_POLYGONM )
01739         return 0;
01740 
01741 /* -------------------------------------------------------------------- */
01742 /*      Process each of the rings.                                      */
01743 /* -------------------------------------------------------------------- */
01744     for( iOpRing = 0; iOpRing < psObject->nParts; iOpRing++ )
01745     {
01746         int      bInner, iVert, nVertCount, nVertStart, iCheckRing;
01747         double   dfSum, dfTestX, dfTestY;
01748 
01749 /* -------------------------------------------------------------------- */
01750 /*      Determine if this ring is an inner ring or an outer ring        */
01751 /*      relative to all the other rings.  For now we assume the         */
01752 /*      first ring is outer and all others are inner, but eventually    */
01753 /*      we need to fix this to handle multiple island polygons and      */
01754 /*      unordered sets of rings.                                        */
01755 /* -------------------------------------------------------------------- */
01756         dfTestX = psObject->padfX[psObject->panPartStart[iOpRing]];
01757         dfTestY = psObject->padfY[psObject->panPartStart[iOpRing]];
01758 
01759         bInner = FALSE;
01760         for( iCheckRing = 0; iCheckRing < psObject->nParts; iCheckRing++ )
01761         {
01762             int iEdge;
01763 
01764             if( iCheckRing == iOpRing )
01765                 continue;
01766             
01767             nVertStart = psObject->panPartStart[iCheckRing];
01768 
01769             if( iCheckRing == psObject->nParts-1 )
01770                 nVertCount = psObject->nVertices 
01771                     - psObject->panPartStart[iCheckRing];
01772             else
01773                 nVertCount = psObject->panPartStart[iCheckRing+1] 
01774                     - psObject->panPartStart[iCheckRing];
01775 
01776             for( iEdge = 0; iEdge < nVertCount; iEdge++ )
01777             {
01778                 int iNext;
01779 
01780                 if( iEdge < nVertCount-1 )
01781                     iNext = iEdge+1;
01782                 else
01783                     iNext = 0;
01784 
01785                 if( (psObject->padfY[iEdge+nVertStart] < dfTestY 
01786                      && psObject->padfY[iNext+nVertStart] >= dfTestY)
01787                     || (psObject->padfY[iNext+nVertStart] < dfTestY 
01788                         && psObject->padfY[iEdge+nVertStart] >= dfTestY) )
01789                 {
01790                     if( psObject->padfX[iEdge+nVertStart] 
01791                         + (dfTestY - psObject->padfY[iEdge+nVertStart])
01792                            / (psObject->padfY[iNext+nVertStart]
01793                               - psObject->padfY[iEdge+nVertStart])
01794                            * (psObject->padfX[iNext+nVertStart]
01795                               - psObject->padfX[iEdge+nVertStart]) < dfTestX )
01796                         bInner = !bInner;
01797                 }
01798             }
01799         }
01800 
01801 /* -------------------------------------------------------------------- */
01802 /*      Determine the current order of this ring so we will know if     */
01803 /*      it has to be reversed.                                          */
01804 /* -------------------------------------------------------------------- */
01805         nVertStart = psObject->panPartStart[iOpRing];
01806 
01807         if( iOpRing == psObject->nParts-1 )
01808             nVertCount = psObject->nVertices - psObject->panPartStart[iOpRing];
01809         else
01810             nVertCount = psObject->panPartStart[iOpRing+1] 
01811                 - psObject->panPartStart[iOpRing];
01812 
01813         dfSum = 0.0;
01814         for( iVert = nVertStart; iVert < nVertStart+nVertCount-1; iVert++ )
01815         {
01816             dfSum += psObject->padfX[iVert] * psObject->padfY[iVert+1]
01817                 - psObject->padfY[iVert] * psObject->padfX[iVert+1];
01818         }
01819 
01820         dfSum += psObject->padfX[iVert] * psObject->padfY[nVertStart]
01821                - psObject->padfY[iVert] * psObject->padfX[nVertStart];
01822 
01823 /* -------------------------------------------------------------------- */
01824 /*      Reverse if necessary.                                           */
01825 /* -------------------------------------------------------------------- */
01826         if( (dfSum < 0.0 && bInner) || (dfSum > 0.0 && !bInner) )
01827         {
01828             int   i;
01829 
01830             bAltered++;
01831             for( i = 0; i < nVertCount/2; i++ )
01832             {
01833                 double dfSaved;
01834 
01835                 /* Swap X */
01836                 dfSaved = psObject->padfX[nVertStart+i];
01837                 psObject->padfX[nVertStart+i] = 
01838                     psObject->padfX[nVertStart+nVertCount-i-1];
01839                 psObject->padfX[nVertStart+nVertCount-i-1] = dfSaved;
01840 
01841                 /* Swap Y */
01842                 dfSaved = psObject->padfY[nVertStart+i];
01843                 psObject->padfY[nVertStart+i] = 
01844                     psObject->padfY[nVertStart+nVertCount-i-1];
01845                 psObject->padfY[nVertStart+nVertCount-i-1] = dfSaved;
01846 
01847                 /* Swap Z */
01848                 if( psObject->padfZ )
01849                 {
01850                     dfSaved = psObject->padfZ[nVertStart+i];
01851                     psObject->padfZ[nVertStart+i] = 
01852                         psObject->padfZ[nVertStart+nVertCount-i-1];
01853                     psObject->padfZ[nVertStart+nVertCount-i-1] = dfSaved;
01854                 }
01855 
01856                 /* Swap M */
01857                 if( psObject->padfM )
01858                 {
01859                     dfSaved = psObject->padfM[nVertStart+i];
01860                     psObject->padfM[nVertStart+i] = 
01861                         psObject->padfM[nVertStart+nVertCount-i-1];
01862                     psObject->padfM[nVertStart+nVertCount-i-1] = dfSaved;
01863                 }
01864             }
01865         }
01866     }
01867 
01868     return bAltered;
01869 }

const char SHPAPI_CALL1* SHPTypeName (  ) 

Definition at line 1606 of file shpopen.c.

References 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.

01609 {
01610     switch( nSHPType )
01611     {
01612       case SHPT_NULL:
01613         return "NullShape";
01614 
01615       case SHPT_POINT:
01616         return "Point";
01617 
01618       case SHPT_ARC:
01619         return "Arc";
01620 
01621       case SHPT_POLYGON:
01622         return "Polygon";
01623 
01624       case SHPT_MULTIPOINT:
01625         return "MultiPoint";
01626         
01627       case SHPT_POINTZ:
01628         return "PointZ";
01629 
01630       case SHPT_ARCZ:
01631         return "ArcZ";
01632 
01633       case SHPT_POLYGONZ:
01634         return "PolygonZ";
01635 
01636       case SHPT_MULTIPOINTZ:
01637         return "MultiPointZ";
01638         
01639       case SHPT_POINTM:
01640         return "PointM";
01641 
01642       case SHPT_ARCM:
01643         return "ArcM";
01644 
01645       case SHPT_POLYGONM:
01646         return "PolygonM";
01647 
01648       case SHPT_MULTIPOINTM:
01649         return "MultiPointM";
01650 
01651       case SHPT_MULTIPATCH:
01652         return "MultiPatch";
01653 
01654       default:
01655         return "UnknownShapeType";
01656     }

static void SHPWriteHeader ( SHPHandle  psSHP  )  [static]

Definition at line 240 of file shpopen.c.

References SHPInfo::adBoundsMax, SHPInfo::adBoundsMin, bBigEndian, ByteCopy, SHPInfo::fpSHP, SHPInfo::fpSHX, fseek(), SHPInfo::nFileSize, SHPInfo::nRecords, SHPInfo::nShapeType, SHPInfo::panRecOffset, SHPInfo::panRecSize, and SwapWord().

Referenced by SHPClose().

00242 {
00243     uchar       abyHeader[100];
00244     int         i;
00245     int32       i32;
00246     double      dValue;
00247     int32       *panSHX;
00248 
00249 /* -------------------------------------------------------------------- */
00250 /*      Prepare header block for .shp file.                             */
00251 /* -------------------------------------------------------------------- */
00252     for( i = 0; i < 100; i++ )
00253       abyHeader[i] = 0;
00254 
00255     abyHeader[2] = 0x27;                                /* magic cookie */
00256     abyHeader[3] = 0x0a;
00257 
00258     i32 = psSHP->nFileSize/2;                           /* file size */
00259     ByteCopy( &i32, abyHeader+24, 4 );
00260     if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
00261     
00262     i32 = 1000;                                         /* version */
00263     ByteCopy( &i32, abyHeader+28, 4 );
00264     if( bBigEndian ) SwapWord( 4, abyHeader+28 );
00265     
00266     i32 = psSHP->nShapeType;                            /* shape type */
00267     ByteCopy( &i32, abyHeader+32, 4 );
00268     if( bBigEndian ) SwapWord( 4, abyHeader+32 );
00269 
00270     dValue = psSHP->adBoundsMin[0];                     /* set bounds */
00271     ByteCopy( &dValue, abyHeader+36, 8 );
00272     if( bBigEndian ) SwapWord( 8, abyHeader+36 );
00273 
00274     dValue = psSHP->adBoundsMin[1];
00275     ByteCopy( &dValue, abyHeader+44, 8 );
00276     if( bBigEndian ) SwapWord( 8, abyHeader+44 );
00277 
00278     dValue = psSHP->adBoundsMax[0];
00279     ByteCopy( &dValue, abyHeader+52, 8 );
00280     if( bBigEndian ) SwapWord( 8, abyHeader+52 );
00281 
00282     dValue = psSHP->adBoundsMax[1];
00283     ByteCopy( &dValue, abyHeader+60, 8 );
00284     if( bBigEndian ) SwapWord( 8, abyHeader+60 );
00285 
00286     dValue = psSHP->adBoundsMin[2];                     /* z */
00287     ByteCopy( &dValue, abyHeader+68, 8 );
00288     if( bBigEndian ) SwapWord( 8, abyHeader+68 );
00289 
00290     dValue = psSHP->adBoundsMax[2];
00291     ByteCopy( &dValue, abyHeader+76, 8 );
00292     if( bBigEndian ) SwapWord( 8, abyHeader+76 );
00293 
00294     dValue = psSHP->adBoundsMin[3];                     /* m */
00295     ByteCopy( &dValue, abyHeader+84, 8 );
00296     if( bBigEndian ) SwapWord( 8, abyHeader+84 );
00297 
00298     dValue = psSHP->adBoundsMax[3];
00299     ByteCopy( &dValue, abyHeader+92, 8 );
00300     if( bBigEndian ) SwapWord( 8, abyHeader+92 );
00301 
00302 /* -------------------------------------------------------------------- */
00303 /*      Write .shp file header.                                         */
00304 /* -------------------------------------------------------------------- */
00305     fseek( psSHP->fpSHP, 0, 0 );
00306     fwrite( abyHeader, 100, 1, psSHP->fpSHP );
00307 
00308 /* -------------------------------------------------------------------- */
00309 /*      Prepare, and write .shx file header.                            */
00310 /* -------------------------------------------------------------------- */
00311     i32 = (psSHP->nRecords * 2 * sizeof(int32) + 100)/2;   /* file size */
00312     ByteCopy( &i32, abyHeader+24, 4 );
00313     if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
00314     
00315     fseek( psSHP->fpSHX, 0, 0 );
00316     fwrite( abyHeader, 100, 1, psSHP->fpSHX );
00317 
00318 /* -------------------------------------------------------------------- */
00319 /*      Write out the .shx contents.                                    */
00320 /* -------------------------------------------------------------------- */
00321     panSHX = (int32 *) malloc(sizeof(int32) * 2 * psSHP->nRecords);
00322 
00323     for( i = 0; i < psSHP->nRecords; i++ )
00324     {
00325         panSHX[i*2  ] = psSHP->panRecOffset[i]/2;
00326         panSHX[i*2+1] = psSHP->panRecSize[i]/2;
00327         if( !bBigEndian ) SwapWord( 4, panSHX+i*2 );
00328         if( !bBigEndian ) SwapWord( 4, panSHX+i*2+1 );
00329     }
00330 
00331     fwrite( panSHX, sizeof(int32) * 2, psSHP->nRecords, psSHP->fpSHX );
00332 
00333     free( panSHX );
00334 }

int SHPAPI_CALL SHPWriteObject ( SHPHandle  psSHP,
int  nShapeId,
SHPObject psObject 
)

Examples:
TePDIRaster2Vector_test.cpp, and TePDISegmentation_test.cpp.

Definition at line 917 of file shpopen.c.

References _SHPSetBounds(), SHPInfo::adBoundsMax, SHPInfo::adBoundsMin, bBigEndian, SHPInfo::bUpdated, ByteCopy, SHPObject::dfMMax, SHPObject::dfMMin, SHPObject::dfZMax, SHPObject::dfZMin, DISABLE_MULTIPATCH_MEASURE, FALSE, SHPInfo::fpSHP, fseek(), MAX, memcpy(), MIN, SHPInfo::nFileSize, SHPInfo::nMaxRecords, SHPObject::nParts, SHPInfo::nRecords, SHPInfo::nShapeType, SHPObject::nSHPType, SHPObject::nVertices, pabyRec, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, SHPObject::panPartStart, SHPObject::panPartType, SHPInfo::panRecOffset, SHPInfo::panRecSize, SfRealloc(), 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, SHPT_POLYGONZ, SwapWord(), and TRUE.

Referenced by exportPS2SHP(), TeExportPolygonSet2SHP(), TeExportQuerierToShapefile(), and TeExportShapefile().

00919 {
00920     int         nRecordOffset, i, nRecordSize;
00921     uchar       *pabyRec;
00922     int32       i32;
00923 
00924     psSHP->bUpdated = TRUE;
00925 
00926 /* -------------------------------------------------------------------- */
00927 /*      Ensure that shape object matches the type of the file it is     */
00928 /*      being written to.                                               */
00929 /* -------------------------------------------------------------------- */
00930     assert( psObject->nSHPType == psSHP->nShapeType 
00931             || psObject->nSHPType == SHPT_NULL );
00932 
00933 /* -------------------------------------------------------------------- */
00934 /*      Ensure that -1 is used for appends.  Either blow an             */
00935 /*      assertion, or if they are disabled, set the shapeid to -1       */
00936 /*      for appends.                                                    */
00937 /* -------------------------------------------------------------------- */
00938     assert( nShapeId == -1 
00939             || (nShapeId >= 0 && nShapeId < psSHP->nRecords) );
00940 
00941     if( nShapeId != -1 && nShapeId >= psSHP->nRecords )
00942         nShapeId = -1;
00943 
00944 /* -------------------------------------------------------------------- */
00945 /*      Add the new entity to the in memory index.                      */
00946 /* -------------------------------------------------------------------- */
00947     if( nShapeId == -1 && psSHP->nRecords+1 > psSHP->nMaxRecords )
00948     {
00949         psSHP->nMaxRecords =(int) ( psSHP->nMaxRecords * 1.3 + 100);
00950 
00951         psSHP->panRecOffset = (int *) 
00952             SfRealloc(psSHP->panRecOffset,sizeof(int) * psSHP->nMaxRecords );
00953         psSHP->panRecSize = (int *) 
00954             SfRealloc(psSHP->panRecSize,sizeof(int) * psSHP->nMaxRecords );
00955     }
00956 
00957 /* -------------------------------------------------------------------- */
00958 /*      Initialize record.                                              */
00959 /* -------------------------------------------------------------------- */
00960     pabyRec = (uchar *) malloc(psObject->nVertices * 4 * sizeof(double) 
00961                                + psObject->nParts * 8 + 128);
00962     
00963 /* -------------------------------------------------------------------- */
00964 /*  Extract vertices for a Polygon or Arc.                              */
00965 /* -------------------------------------------------------------------- */
00966     if( psObject->nSHPType == SHPT_POLYGON
00967         || psObject->nSHPType == SHPT_POLYGONZ
00968         || psObject->nSHPType == SHPT_POLYGONM
00969         || psObject->nSHPType == SHPT_ARC 
00970         || psObject->nSHPType == SHPT_ARCZ
00971         || psObject->nSHPType == SHPT_ARCM
00972         || psObject->nSHPType == SHPT_MULTIPATCH )
00973     {
00974         int32           nPoints, nParts;
00975         int             i;
00976 
00977         nPoints = psObject->nVertices;
00978         nParts = psObject->nParts;
00979 
00980         _SHPSetBounds( pabyRec + 12, psObject );
00981 
00982         if( bBigEndian ) SwapWord( 4, &nPoints );
00983         if( bBigEndian ) SwapWord( 4, &nParts );
00984 
00985         ByteCopy( &nPoints, pabyRec + 40 + 8, 4 );
00986         ByteCopy( &nParts, pabyRec + 36 + 8, 4 );
00987 
00988         nRecordSize = 52;
00989 
00990         /*
00991          * Write part start positions.
00992          */
00993         ByteCopy( psObject->panPartStart, pabyRec + 44 + 8,
00994                   4 * psObject->nParts );
00995         for( i = 0; i < psObject->nParts; i++ )
00996         {
00997             if( bBigEndian ) SwapWord( 4, pabyRec + 44 + 8 + 4*i );
00998             nRecordSize += 4;
00999         }
01000 
01001         /*
01002          * Write multipatch part types if needed.
01003          */
01004         if( psObject->nSHPType == SHPT_MULTIPATCH )
01005         {
01006             memcpy( pabyRec + nRecordSize, psObject->panPartType,
01007                     4*psObject->nParts );
01008             for( i = 0; i < psObject->nParts; i++ )
01009             {
01010                 if( bBigEndian ) SwapWord( 4, pabyRec + nRecordSize );
01011                 nRecordSize += 4;
01012             }
01013         }
01014 
01015         /*
01016          * Write the (x,y) vertex values.
01017          */
01018         for( i = 0; i < psObject->nVertices; i++ )
01019         {
01020             ByteCopy( psObject->padfX + i, pabyRec + nRecordSize, 8 );
01021             ByteCopy( psObject->padfY + i, pabyRec + nRecordSize + 8, 8 );
01022 
01023             if( bBigEndian )
01024                 SwapWord( 8, pabyRec + nRecordSize );
01025             
01026             if( bBigEndian )
01027                 SwapWord( 8, pabyRec + nRecordSize + 8 );
01028 
01029             nRecordSize += 2 * 8;
01030         }
01031 
01032         /*
01033          * Write the Z coordinates (if any).
01034          */
01035         if( psObject->nSHPType == SHPT_POLYGONZ
01036             || psObject->nSHPType == SHPT_ARCZ
01037             || psObject->nSHPType == SHPT_MULTIPATCH )
01038         {
01039             ByteCopy( &(psObject->dfZMin), pabyRec + nRecordSize, 8 );
01040             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01041             nRecordSize += 8;
01042             
01043             ByteCopy( &(psObject->dfZMax), pabyRec + nRecordSize, 8 );
01044             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01045             nRecordSize += 8;
01046 
01047             for( i = 0; i < psObject->nVertices; i++ )
01048             {
01049                 ByteCopy( psObject->padfZ + i, pabyRec + nRecordSize, 8 );
01050                 if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01051                 nRecordSize += 8;
01052             }
01053         }
01054 
01055         /*
01056          * Write the M values, if any.
01057          */
01058         if( psObject->nSHPType == SHPT_POLYGONM
01059             || psObject->nSHPType == SHPT_ARCM
01060 #ifndef DISABLE_MULTIPATCH_MEASURE            
01061             || psObject->nSHPType == SHPT_MULTIPATCH
01062 #endif            
01063             || psObject->nSHPType == SHPT_POLYGONZ
01064             || psObject->nSHPType == SHPT_ARCZ )
01065         {
01066             ByteCopy( &(psObject->dfMMin), pabyRec + nRecordSize, 8 );
01067             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01068             nRecordSize += 8;
01069             
01070             ByteCopy( &(psObject->dfMMax), pabyRec + nRecordSize, 8 );
01071             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01072             nRecordSize += 8;
01073 
01074             for( i = 0; i < psObject->nVertices; i++ )
01075             {
01076                 ByteCopy( psObject->padfM + i, pabyRec + nRecordSize, 8 );
01077                 if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01078                 nRecordSize += 8;
01079             }
01080         }
01081     }
01082 
01083 /* -------------------------------------------------------------------- */
01084 /*  Extract vertices for a MultiPoint.                                  */
01085 /* -------------------------------------------------------------------- */
01086     else if( psObject->nSHPType == SHPT_MULTIPOINT
01087              || psObject->nSHPType == SHPT_MULTIPOINTZ
01088              || psObject->nSHPType == SHPT_MULTIPOINTM )
01089     {
01090         int32           nPoints;
01091         int             i;
01092 
01093         nPoints = psObject->nVertices;
01094 
01095         _SHPSetBounds( pabyRec + 12, psObject );
01096 
01097         if( bBigEndian ) SwapWord( 4, &nPoints );
01098         ByteCopy( &nPoints, pabyRec + 44, 4 );
01099         
01100         for( i = 0; i < psObject->nVertices; i++ )
01101         {
01102             ByteCopy( psObject->padfX + i, pabyRec + 48 + i*16, 8 );
01103             ByteCopy( psObject->padfY + i, pabyRec + 48 + i*16 + 8, 8 );
01104 
01105             if( bBigEndian ) SwapWord( 8, pabyRec + 48 + i*16 );
01106             if( bBigEndian ) SwapWord( 8, pabyRec + 48 + i*16 + 8 );
01107         }
01108 
01109         nRecordSize = 48 + 16 * psObject->nVertices;
01110 
01111         if( psObject->nSHPType == SHPT_MULTIPOINTZ )
01112         {
01113             ByteCopy( &(psObject->dfZMin), pabyRec + nRecordSize, 8 );
01114             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01115             nRecordSize += 8;
01116 
01117             ByteCopy( &(psObject->dfZMax), pabyRec + nRecordSize, 8 );
01118             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01119             nRecordSize += 8;
01120             
01121             for( i = 0; i < psObject->nVertices; i++ )
01122             {
01123                 ByteCopy( psObject->padfZ + i, pabyRec + nRecordSize, 8 );
01124                 if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01125                 nRecordSize += 8;
01126             }
01127         }
01128 
01129         if( psObject->nSHPType == SHPT_MULTIPOINTZ
01130             || psObject->nSHPType == SHPT_MULTIPOINTM )
01131         {
01132             ByteCopy( &(psObject->dfMMin), pabyRec + nRecordSize, 8 );
01133             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01134             nRecordSize += 8;
01135 
01136             ByteCopy( &(psObject->dfMMax), pabyRec + nRecordSize, 8 );
01137             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01138             nRecordSize += 8;
01139             
01140             for( i = 0; i < psObject->nVertices; i++ )
01141             {
01142                 ByteCopy( psObject->padfM + i, pabyRec + nRecordSize, 8 );
01143                 if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01144                 nRecordSize += 8;
01145             }
01146         }
01147     }
01148 
01149 /* -------------------------------------------------------------------- */
01150 /*      Write point.                                                    */
01151 /* -------------------------------------------------------------------- */
01152     else if( psObject->nSHPType == SHPT_POINT
01153              || psObject->nSHPType == SHPT_POINTZ
01154              || psObject->nSHPType == SHPT_POINTM )
01155     {
01156         ByteCopy( psObject->padfX, pabyRec + 12, 8 );
01157         ByteCopy( psObject->padfY, pabyRec + 20, 8 );
01158 
01159         if( bBigEndian ) SwapWord( 8, pabyRec + 12 );
01160         if( bBigEndian ) SwapWord( 8, pabyRec + 20 );
01161 
01162         nRecordSize = 28;
01163         
01164         if( psObject->nSHPType == SHPT_POINTZ )
01165         {
01166             ByteCopy( psObject->padfZ, pabyRec + nRecordSize, 8 );
01167             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01168             nRecordSize += 8;
01169         }
01170         
01171         if( psObject->nSHPType == SHPT_POINTZ
01172             || psObject->nSHPType == SHPT_POINTM )
01173         {
01174             ByteCopy( psObject->padfM, pabyRec + nRecordSize, 8 );
01175             if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
01176             nRecordSize += 8;
01177         }
01178     }
01179 
01180 /* -------------------------------------------------------------------- */
01181 /*      Not much to do for null geometries.                             */
01182 /* -------------------------------------------------------------------- */
01183     else if( psObject->nSHPType == SHPT_NULL )
01184     {
01185         nRecordSize = 12;
01186     }
01187 
01188     else
01189     {
01190         /* unknown type */
01191         assert( FALSE );
01192     }
01193 
01194 /* -------------------------------------------------------------------- */
01195 /*      Establish where we are going to put this record. If we are      */
01196 /*      rewriting and existing record, and it will fit, then put it     */
01197 /*      back where the original came from.  Otherwise write at the end. */
01198 /* -------------------------------------------------------------------- */
01199     if( nShapeId == -1 || psSHP->panRecSize[nShapeId] < nRecordSize-8 )
01200     {
01201         if( nShapeId == -1 )
01202             nShapeId = psSHP->nRecords++;
01203 
01204         psSHP->panRecOffset[nShapeId] = nRecordOffset = psSHP->nFileSize;
01205         psSHP->panRecSize[nShapeId] = nRecordSize-8;
01206         psSHP->nFileSize += nRecordSize;
01207     }
01208     else
01209     {
01210         nRecordOffset = psSHP->panRecOffset[nShapeId];
01211     }
01212     
01213 /* -------------------------------------------------------------------- */
01214 /*      Set the shape type, record number, and record size.             */
01215 /* -------------------------------------------------------------------- */
01216     i32 = nShapeId+1;                                   /* record # */
01217     if( !bBigEndian ) SwapWord( 4, &i32 );
01218     ByteCopy( &i32, pabyRec, 4 );
01219 
01220     i32 = (nRecordSize-8)/2;                            /* record size */
01221     if( !bBigEndian ) SwapWord( 4, &i32 );
01222     ByteCopy( &i32, pabyRec + 4, 4 );
01223 
01224     i32 = psObject->nSHPType;                           /* shape type */
01225     if( bBigEndian ) SwapWord( 4, &i32 );
01226     ByteCopy( &i32, pabyRec + 8, 4 );
01227 
01228 /* -------------------------------------------------------------------- */
01229 /*      Write out record.                                               */
01230 /* -------------------------------------------------------------------- */
01231     if( fseek( psSHP->fpSHP, nRecordOffset, 0 ) != 0
01232         || fwrite( pabyRec, nRecordSize, 1, psSHP->fpSHP ) < 1 )
01233     {
01234         printf( "Error in fseek() or fwrite().\n" );
01235         free( pabyRec );
01236         return -1;
01237     }
01238     
01239     free( pabyRec );
01240 
01241 /* -------------------------------------------------------------------- */
01242 /*      Expand file wide bounds based on this shape.                    */
01243 /* -------------------------------------------------------------------- */
01244     if( psSHP->adBoundsMin[0] == 0.0
01245         && psSHP->adBoundsMax[0] == 0.0
01246         && psSHP->adBoundsMin[1] == 0.0
01247         && psSHP->adBoundsMax[1] == 0.0 
01248         && psObject->nSHPType != SHPT_NULL )
01249     {
01250         psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = psObject->padfX[0];
01251         psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = psObject->padfY[0];
01252         psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = psObject->padfZ[0];
01253         psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = psObject->padfM[0];
01254     }
01255 
01256     for( i = 0; i < psObject->nVertices; i++ )
01257     {
01258         psSHP->adBoundsMin[0] = MIN(psSHP->adBoundsMin[0],psObject->padfX[i]);
01259         psSHP->adBoundsMin[1] = MIN(psSHP->adBoundsMin[1],psObject->padfY[i]);
01260         psSHP->adBoundsMin[2] = MIN(psSHP->adBoundsMin[2],psObject->padfZ[i]);
01261         psSHP->adBoundsMin[3] = MIN(psSHP->adBoundsMin[3],psObject->padfM[i]);
01262         psSHP->adBoundsMax[0] = MAX(psSHP->adBoundsMax[0],psObject->padfX[i]);
01263         psSHP->adBoundsMax[1] = MAX(psSHP->adBoundsMax[1],psObject->padfY[i]);
01264         psSHP->adBoundsMax[2] = MAX(psSHP->adBoundsMax[2],psObject->padfZ[i]);
01265         psSHP->adBoundsMax[3] = MAX(psSHP->adBoundsMax[3],psObject->padfM[i]);
01266     }
01267 
01268     return( nShapeId  );
01269 }

static void SwapWord ( int  length,
void *  wordP 
) [static]

Definition at line 203 of file shpopen.c.

Referenced by _SHPSetBounds(), if(), SHPCreate(), SHPOpen(), SHPWriteHeader(), and SHPWriteObject().

00205 {
00206     int         i;
00207     uchar       temp;
00208 
00209     for( i=0; i < length/2; i++ )
00210     {
00211         temp = ((uchar *) wordP)[i];
00212         ((uchar *)wordP)[i] = ((uchar *) wordP)[length-i-1];
00213         ((uchar *) wordP)[length-i-1] = temp;
00214     }
00215 }


Variable Documentation

int bBigEndian [static]

Definition at line 194 of file shpopen.c.

Referenced by _SHPSetBounds(), if(), SHPCreate(), SHPOpen(), SHPWriteHeader(), and SHPWriteObject().

psShape nShapeId = hEntity

Definition at line 1309 of file shpopen.c.

psObject nShapeId = nShapeId

Definition at line 801 of file shpopen.c.

psObject nSHPType = nSHPType

Definition at line 800 of file shpopen.c.

psShape = (SHPObject *) calloc(1,sizeof(SHPObject))

Definition at line 1308 of file shpopen.c.

Referenced by TeQuerierSHP::fetchInstance(), TeShapefileDriver::loadData(), TeImportShape(), TeImportShapeGeometry(), and TeSTOSetBuildSHP().


Generated on Sun Jul 29 04:02:13 2012 for TerraLib - Development Source by  doxygen 1.5.3