485 char *pszFullname, *pszBasename;
497 if( strcmp(pszAccess,
"rb+") == 0 || strcmp(pszAccess,
"r+b") == 0
498 || strcmp(pszAccess,
"r+") == 0 )
507 if( *((
uchar *) &i) == 1 )
524 pszBasename = (
char *)
malloc(strlen(pszLayer)+5);
525 strcpy( pszBasename, pszLayer );
526 for( i = strlen(pszBasename)-1;
527 i > 0 && pszBasename[i] !=
'.' && pszBasename[i] !=
'/' 528 && pszBasename[i] !=
'\\';
531 if( pszBasename[i] ==
'.' )
532 pszBasename[i] =
'\0';
538 pszFullname = (
char *)
malloc(strlen(pszBasename) + 5);
539 sprintf( pszFullname,
"%s.shp", pszBasename ) ;
541 if( psSHP->
fpSHP == NULL )
543 sprintf( pszFullname,
"%s.SHP", pszBasename );
547 if( psSHP->
fpSHP == NULL )
549 char *pszMessage = (
char *)
malloc(strlen(pszBasename)*2+256);
550 sprintf( pszMessage,
"Unable to open %s.shp or %s.SHP.",
551 pszBasename, pszBasename );
552 psHooks->
Error( pszMessage );
560 sprintf( pszFullname,
"%s.shx", pszBasename );
562 if( psSHP->
fpSHX == NULL )
564 sprintf( pszFullname,
"%s.SHX", pszBasename );
568 if( psSHP->
fpSHX == NULL )
570 char *pszMessage = (
char *)
malloc(strlen(pszBasename)*2+256);
571 sprintf( pszMessage,
"Unable to open %s.shx or %s.SHX.",
572 pszBasename, pszBasename );
573 psHooks->
Error( pszMessage );
592 psSHP->
nFileSize = ((
unsigned int)pabyBuf[24] * 256 * 256 * 256
593 + (
unsigned int)pabyBuf[25] * 256 * 256
594 + (
unsigned int)pabyBuf[26] * 256
595 + (
unsigned int)pabyBuf[27]) * 2;
603 || pabyBuf[2] != 0x27
604 || (pabyBuf[3] != 0x0a && pabyBuf[3] != 0x0d) )
606 psSHP->
sHooks.
Error(
".shx file is unreadable, or corrupt." );
614 psSHP->
nRecords = pabyBuf[27] + pabyBuf[26] * 256
615 + pabyBuf[25] * 256 * 256 + pabyBuf[24] * 256 * 256 * 256;
625 "Record count in .shp header is %d, which seems\n" 626 "unreasonable. Assuming header is corrupt.",
641 memcpy( &dValue, pabyBuf+36, 8 );
645 memcpy( &dValue, pabyBuf+44, 8 );
649 memcpy( &dValue, pabyBuf+52, 8 );
653 memcpy( &dValue, pabyBuf+60, 8 );
657 memcpy( &dValue, pabyBuf+68, 8 );
661 memcpy( &dValue, pabyBuf+76, 8 );
665 memcpy( &dValue, pabyBuf+84, 8 );
669 memcpy( &dValue, pabyBuf+92, 8 );
693 "Not enough memory to allocate requested memory (nRecords=%d).\n" 694 "Probably broken SHP file",
701 if (pabyBuf)
free( pabyBuf );
712 "Failed to read all values for %d records in .shx file.",
728 if (strcmp(pszAccess,
"rb") == 0)
734 for( i = 0; i < psSHP->
nRecords; i++ )
736 int32 nOffset, nLength;
738 memcpy( &nOffset, pabyBuf + i * 8, 4 );
741 memcpy( &nLength, pabyBuf + i * 8 + 4, 4 );
int(* FClose)(SAFile file)
unsigned int * panRecOffset
unsigned int * panRecSize
SAFile(* FOpen)(const char *filename, const char *access)
static void SwapWord(int length, void *wordP)
void(* Error)(const char *message)
SAOffset(* FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file)