MCPcopy Index your code
hub / github.com/MapServer/MapServer / msSHXLoadPage

Function msSHXLoadPage

mapshape.c:1076–1122  ·  view source on GitHub ↗

** msSHXLoadPage() ** ** The SHX tells us what the byte offsets of the shapes in the SHP file are. ** We read the SHX file in ~8K pages and store those pages in memory for ** successive accesses during the reading cycle (first bounds are read, ** then entire shapes). Each time we read a page, we mark it as read. */

Source from the content-addressed store, hash-verified

1074** then entire shapes). Each time we read a page, we mark it as read.
1075*/
1076int msSHXLoadPage( SHPHandle psSHP, int shxBufferPage )
1077{
1078 int i;
1079
1080 /* Each SHX record is 8 bytes long (two ints), hence our buffer size. */
1081 char buffer[SHX_BUFFER_PAGE * 8];
1082
1083 /* Validate the page number. */
1084 if( shxBufferPage < 0 )
1085 return(MS_FAILURE);
1086
1087 /* The SHX file starts with 100 bytes of header, skip that. */
1088 fseek( psSHP->fpSHX, 100 + shxBufferPage * SHX_BUFFER_PAGE * 8, 0 );
1089 fread( buffer, 8, SHX_BUFFER_PAGE, psSHP->fpSHX );
1090
1091 /* Copy the buffer contents out into the working arrays. */
1092 for( i = 0; i < SHX_BUFFER_PAGE; i++ ) {
1093 int tmpOffset, tmpSize;
1094
1095 /* Don't write information past the end of the arrays, please. */
1096 if(psSHP->nRecords <= (shxBufferPage * SHX_BUFFER_PAGE + i) )
1097 break;
1098
1099 memcpy( &tmpOffset, (buffer + (8*i)), 4);
1100 memcpy( &tmpSize, (buffer + (8*i) + 4), 4);
1101
1102 /* SHX uses big endian numbers for the offsets, so we have to flip them */
1103 /* if we are a little endian machine. */
1104 if( !bBigEndian ) {
1105 tmpOffset = SWAP_FOUR_BYTES(tmpOffset);
1106 tmpSize = SWAP_FOUR_BYTES(tmpSize);
1107 }
1108
1109 /* SHX stores the offsets in 2 byte units, so we double them to get */
1110 /* an offset in bytes. */
1111 tmpOffset = tmpOffset * 2;
1112 tmpSize = tmpSize * 2;
1113
1114 /* Write the answer into the working arrays on the SHPHandle */
1115 psSHP->panRecOffset[shxBufferPage * SHX_BUFFER_PAGE + i] = tmpOffset;
1116 psSHP->panRecSize[shxBufferPage * SHX_BUFFER_PAGE + i] = tmpSize;
1117 }
1118
1119 msSetBit(psSHP->panRecLoaded, shxBufferPage, 1);
1120
1121 return(MS_SUCCESS);
1122}
1123
1124int msSHXLoadAll( SHPHandle psSHP ) {
1125

Callers 2

msSHXReadOffsetFunction · 0.85
msSHXReadSizeFunction · 0.85

Calls 1

msSetBitFunction · 0.85

Tested by

no test coverage detected