266 SHP_CVSID(
"$Id: shpopen.c 15750 2017-09-17 20:59:20Z strk $")
270 #if UINT_MAX == 65535 271 typedef unsigned long int32;
281 #define ByteCopy( a, b, c ) memcpy( b, a, c ) 283 # define MIN(a,b) ((a<b) ? a : b) 284 # define MAX(a,b) ((a>b) ? a : b) 287 #if defined(WIN32) || defined(_WIN32) 289 # define snprintf _snprintf 308 for( i=0; i < length/2; i++ )
310 temp = ((uchar *) wordP)[i];
311 ((uchar *)wordP)[i] = ((uchar *) wordP)[length-i-1];
312 ((uchar *) wordP)[length-i-1] = temp;
327 return( (
void *)
malloc(nNewSize) );
329 return( (
void *) realloc(pMem,nNewSize) );
342 uchar abyHeader[100];
348 if (psSHP->
fpSHX == NULL)
350 psSHP->
sHooks.
Error(
"SHPWriteHeader failed : SHX file is closed");
357 for( i = 0; i < 100; i++ )
365 if( !bBigEndian )
SwapWord( 4, abyHeader+24 );
369 if( bBigEndian )
SwapWord( 4, abyHeader+28 );
373 if( bBigEndian )
SwapWord( 4, abyHeader+32 );
376 ByteCopy( &dValue, abyHeader+36, 8 );
377 if( bBigEndian )
SwapWord( 8, abyHeader+36 );
380 ByteCopy( &dValue, abyHeader+44, 8 );
381 if( bBigEndian )
SwapWord( 8, abyHeader+44 );
384 ByteCopy( &dValue, abyHeader+52, 8 );
385 if( bBigEndian )
SwapWord( 8, abyHeader+52 );
388 ByteCopy( &dValue, abyHeader+60, 8 );
389 if( bBigEndian )
SwapWord( 8, abyHeader+60 );
392 ByteCopy( &dValue, abyHeader+68, 8 );
393 if( bBigEndian )
SwapWord( 8, abyHeader+68 );
396 ByteCopy( &dValue, abyHeader+76, 8 );
397 if( bBigEndian )
SwapWord( 8, abyHeader+76 );
400 ByteCopy( &dValue, abyHeader+84, 8 );
401 if( bBigEndian )
SwapWord( 8, abyHeader+84 );
404 ByteCopy( &dValue, abyHeader+92, 8 );
405 if( bBigEndian )
SwapWord( 8, abyHeader+92 );
413 psSHP->
sHooks.
Error(
"Failure writing .shp header" );
422 if( !bBigEndian )
SwapWord( 4, abyHeader+24 );
427 psSHP->
sHooks.
Error(
"Failure writing .shx header" );
436 for( i = 0; i < psSHP->
nRecords; i++ )
440 if( !bBigEndian )
SwapWord( 4, panSHX+i*2 );
441 if( !bBigEndian )
SwapWord( 4, panSHX+i*2+1 );
447 psSHP->
sHooks.
Error(
"Failure writing .shx contents" );
464 SHPOpen(
const char * pszLayer,
const char * pszAccess )
471 return SHPOpenLL( pszLayer, pszAccess, &sHooks );
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 );
589 pabyBuf = (uchar *)
malloc(100);
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.",
640 if( bBigEndian )
SwapWord( 8, pabyBuf+36 );
641 memcpy( &dValue, pabyBuf+36, 8 );
644 if( bBigEndian )
SwapWord( 8, pabyBuf+44 );
645 memcpy( &dValue, pabyBuf+44, 8 );
648 if( bBigEndian )
SwapWord( 8, pabyBuf+52 );
649 memcpy( &dValue, pabyBuf+52, 8 );
652 if( bBigEndian )
SwapWord( 8, pabyBuf+60 );
653 memcpy( &dValue, pabyBuf+60, 8 );
656 if( bBigEndian )
SwapWord( 8, pabyBuf+68 );
657 memcpy( &dValue, pabyBuf+68, 8 );
660 if( bBigEndian )
SwapWord( 8, pabyBuf+76 );
661 memcpy( &dValue, pabyBuf+76, 8 );
664 if( bBigEndian )
SwapWord( 8, pabyBuf+84 );
665 memcpy( &dValue, pabyBuf+84, 8 );
668 if( bBigEndian )
SwapWord( 8, pabyBuf+92 );
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 );
739 if( !bBigEndian )
SwapWord( 4, &nOffset );
741 memcpy( &nLength, pabyBuf + i * 8 + 4, 4 );
742 if( !bBigEndian )
SwapWord( 4, &nLength );
777 if ( psSHP->
fpSHX != NULL)
797 double * padfMinBound,
double * padfMaxBound )
805 if( pnEntities != NULL )
808 if( pnShapeType != NULL )
811 for( i = 0; i < 4; i++ )
813 if( padfMinBound != NULL )
815 if( padfMaxBound != NULL )
835 return SHPCreateLL( pszLayer, nShapeType, &sHooks );
849 char *pszBasename = NULL, *pszFullname = NULL;
851 SAFile fpSHP = NULL, fpSHX = NULL;
852 uchar abyHeader[100];
860 if( *((uchar *) &i) == 1 )
869 pszBasename = (
char *)
malloc(strlen(pszLayer)+5);
870 strcpy( pszBasename, pszLayer );
871 for( i = strlen(pszBasename)-1;
872 i > 0 && pszBasename[i] !=
'.' && pszBasename[i] !=
'/' 873 && pszBasename[i] !=
'\\';
876 if( pszBasename[i] ==
'.' )
877 pszBasename[i] =
'\0';
882 pszFullname = (
char *)
malloc(strlen(pszBasename) + 5);
883 sprintf( pszFullname,
"%s.shp", pszBasename );
884 fpSHP = psHooks->
FOpen(pszFullname,
"wb" );
887 psHooks->
Error(
"Failed to create file .shp file." );
891 sprintf( pszFullname,
"%s.shx", pszBasename );
892 fpSHX = psHooks->
FOpen(pszFullname,
"wb" );
895 psHooks->
Error(
"Failed to create file .shx file." );
899 free( pszFullname ); pszFullname = NULL;
900 free( pszBasename ); pszBasename = NULL;
905 for( i = 0; i < 100; i++ )
913 if( !bBigEndian )
SwapWord( 4, abyHeader+24 );
917 if( bBigEndian )
SwapWord( 4, abyHeader+28 );
921 if( bBigEndian )
SwapWord( 4, abyHeader+32 );
924 ByteCopy( &dValue, abyHeader+36, 8 );
925 ByteCopy( &dValue, abyHeader+44, 8 );
926 ByteCopy( &dValue, abyHeader+52, 8 );
927 ByteCopy( &dValue, abyHeader+60, 8 );
932 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHP ) != 1 )
934 psHooks->
Error(
"Failed to write .shp header." );
943 if( !bBigEndian )
SwapWord( 4, abyHeader+24 );
945 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHX ) != 1 )
947 psHooks->
Error(
"Failed to write .shx header." );
957 return(
SHPOpenLL( pszLayer,
"r+b", psHooks ) );
960 if (pszFullname)
free(pszFullname);
961 if (pszBasename)
free(pszBasename);
962 if (fpSHP) psHooks->
FClose( fpSHP );
963 if (fpSHX) psHooks->
FClose( fpSHX );
1015 for( i = 0; i < psObject->
nVertices; i++ )
1038 const int * panPartStart,
const int * panPartType,
1039 int nVertices,
const double *padfX,
const double *padfY,
1040 const double * padfZ,
const double * padfM )
1044 int i, bHasM,
bHasZ;
1089 calloc(
sizeof(
int), psObject->
nParts);
1096 for( i = 0; i < nParts; i++ )
1101 if( panPartType != NULL )
1124 psObject->
padfX[i] = padfX[i];
1126 psObject->
padfY[i] = padfY[i];
1127 if( padfZ != NULL && bHasZ )
1128 psObject->
padfZ[i] = padfZ[i];
1129 if( padfM != NULL && bHasM )
1130 psObject->
padfM[i] = padfM[i];
1132 if( padfM != NULL && bHasM )
1154 const
double * padfX, const
double * padfY,
1155 const
double * padfZ )
1159 nVertices, padfX, padfY, padfZ, NULL ) );
1173 unsigned int nRecordOffset, nRecordSize=0;
1192 assert( nShapeId == -1
1193 || (nShapeId >= 0 && nShapeId < psSHP->nRecords) );
1195 if( nShapeId != -1 && nShapeId >= psSHP->
nRecords )
1215 + psObject->
nParts * 8 + 128);
1228 int32 nPoints, nParts;
1232 nParts = psObject->
nParts;
1236 if( bBigEndian )
SwapWord( 4, &nPoints );
1237 if( bBigEndian )
SwapWord( 4, &nParts );
1239 ByteCopy( &nPoints, pabyRec + 40 + 8, 4 );
1240 ByteCopy( &nParts, pabyRec + 36 + 8, 4 );
1249 for( i = 0; i < psObject->
nParts; i++ )
1251 if( bBigEndian )
SwapWord( 4, pabyRec + 44 + 8 + 4*i );
1260 memcpy( pabyRec + nRecordSize, psObject->
panPartType,
1262 for( i = 0; i < psObject->
nParts; i++ )
1264 if( bBigEndian )
SwapWord( 4, pabyRec + nRecordSize );
1272 for( i = 0; i < psObject->
nVertices; i++ )
1275 ByteCopy( psObject->
padfY + i, pabyRec + nRecordSize + 8, 8 );
1278 SwapWord( 8, pabyRec + nRecordSize );
1281 SwapWord( 8, pabyRec + nRecordSize + 8 );
1283 nRecordSize += 2 * 8;
1294 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1298 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1301 for( i = 0; i < psObject->
nVertices; i++ )
1304 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1322 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1326 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1329 for( i = 0; i < psObject->
nVertices; i++ )
1332 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1352 if( bBigEndian )
SwapWord( 4, &nPoints );
1353 ByteCopy( &nPoints, pabyRec + 44, 4 );
1355 for( i = 0; i < psObject->
nVertices; i++ )
1358 ByteCopy( psObject->
padfY + i, pabyRec + 48 + i*16 + 8, 8 );
1360 if( bBigEndian )
SwapWord( 8, pabyRec + 48 + i*16 );
1361 if( bBigEndian )
SwapWord( 8, pabyRec + 48 + i*16 + 8 );
1364 nRecordSize = 48 + 16 * psObject->
nVertices;
1369 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1373 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1376 for( i = 0; i < psObject->
nVertices; i++ )
1379 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1389 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1393 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1396 for( i = 0; i < psObject->
nVertices; i++ )
1399 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1415 if( bBigEndian )
SwapWord( 8, pabyRec + 12 );
1416 if( bBigEndian )
SwapWord( 8, pabyRec + 20 );
1423 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1432 if( bBigEndian )
SwapWord( 8, pabyRec + nRecordSize );
1456 if( nShapeId == -1 || psSHP->
panRecSize[nShapeId] < nRecordSize-8 )
1458 unsigned int nExpectedSize = psSHP->
nFileSize + nRecordSize;
1459 if( nExpectedSize < psSHP->nFileSize )
1462 sprintf( str,
"Failed to write shape object. " 1463 "File size cannot reach %u + %u.",
1470 if( nShapeId == -1 )
1487 if( !bBigEndian )
SwapWord( 4, &i32 );
1490 i32 = (nRecordSize-8)/2;
1491 if( !bBigEndian )
SwapWord( 4, &i32 );
1495 if( bBigEndian )
SwapWord( 4, &i32 );
1503 psSHP->
sHooks.
Error(
"Error in psSHP->sHooks.FSeek() while writing object to .shp file." );
1509 psSHP->
sHooks.
Error(
"Error in psSHP->sHooks.Fwrite() while writing object to .shp file." );
1540 for( i = 0; i < psObject->
nVertices; i++ )
1568 char szErrorMsg[128];
1573 if( hEntity < 0 || hEntity >= psSHP->
nRecords )
1591 "Not enough memory to allocate requested memory (nBufSize=%d). " 1592 "Probably broken SHP file", psSHP->
nBufSize );
1618 "Error in fseek() reading object from .shp file at offset %u",
1633 "Error in fread() reading object of size %u at offset %u from .shp file",
1647 if ( 8 + 4 > nEntitySize )
1649 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1650 "Corrupted .shp file : shape %d : nEntitySize = %d",
1651 hEntity, nEntitySize);
1670 int32 nPoints, nParts;
1673 if ( 40 + 8 + 4 > nEntitySize )
1675 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1676 "Corrupted .shp file : shape %d : nEntitySize = %d",
1677 hEntity, nEntitySize);
1699 memcpy( &nPoints, psSHP->
pabyRec + 40 + 8, 4 );
1700 memcpy( &nParts, psSHP->
pabyRec + 36 + 8, 4 );
1702 if( bBigEndian )
SwapWord( 4, &nPoints );
1703 if( bBigEndian )
SwapWord( 4, &nParts );
1705 if (nPoints > 50 * 1000 * 1000 || nParts > 10 * 1000 * 1000)
1707 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1708 "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d.",
1709 hEntity, nPoints, nParts);
1718 nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
1723 nRequiredSize += 16 + 8 * nPoints;
1727 nRequiredSize += 4 * nParts;
1729 if (nRequiredSize > nEntitySize)
1731 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1732 "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d, nEntitySize=%d.",
1733 hEntity, nPoints, nParts, nEntitySize);
1740 psShape->
padfX = (
double *) calloc(nPoints,
sizeof(
double));
1741 psShape->
padfY = (
double *) calloc(nPoints,
sizeof(
double));
1742 psShape->
padfZ = (
double *) calloc(nPoints,
sizeof(
double));
1743 psShape->
padfM = (
double *) calloc(nPoints,
sizeof(
double));
1745 psShape->
nParts = nParts;
1746 psShape->
panPartStart = (
int *) calloc(nParts,
sizeof(
int));
1747 psShape->
panPartType = (
int *) calloc(nParts,
sizeof(
int));
1749 if (psShape->
padfX == NULL ||
1750 psShape->
padfY == NULL ||
1751 psShape->
padfZ == NULL ||
1752 psShape->
padfM == NULL ||
1756 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1757 "Not enough memory to allocate requested memory (nPoints=%d, nParts=%d) for shape %d. " 1758 "Probably broken SHP file", hEntity, nPoints, nParts );
1764 for( i = 0; i < nParts; i++ )
1771 for( i = 0; i < nParts; i++ )
1780 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1781 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
1789 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1790 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
1798 nOffset = 44 + 8 + 4*nParts;
1806 for( i = 0; i < nParts; i++ )
1811 nOffset += 4*nParts;
1817 for( i = 0; i < nPoints; i++ )
1819 memcpy(psShape->
padfX + i,
1820 psSHP->
pabyRec + nOffset + i * 16,
1823 memcpy(psShape->
padfY + i,
1824 psSHP->
pabyRec + nOffset + i * 16 + 8,
1831 nOffset += 16*nPoints;
1841 memcpy( &(psShape->
dfZMax), psSHP->
pabyRec + nOffset + 8, 8 );
1846 for( i = 0; i < nPoints; i++ )
1848 memcpy( psShape->
padfZ + i,
1849 psSHP->
pabyRec + nOffset + 16 + i*8, 8 );
1853 nOffset += 16 + 8*nPoints;
1862 if( nEntitySize >= nOffset + 16 + 8*nPoints )
1865 memcpy( &(psShape->
dfMMax), psSHP->
pabyRec + nOffset + 8, 8 );
1870 for( i = 0; i < nPoints; i++ )
1872 memcpy( psShape->
padfM + i,
1873 psSHP->
pabyRec + nOffset + 16 + i*8, 8 );
1890 if ( 44 + 4 > nEntitySize )
1892 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1893 "Corrupted .shp file : shape %d : nEntitySize = %d",
1894 hEntity, nEntitySize);
1899 memcpy( &nPoints, psSHP->
pabyRec + 44, 4 );
1901 if( bBigEndian )
SwapWord( 4, &nPoints );
1903 if (nPoints > 50 * 1000 * 1000)
1905 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1906 "Corrupted .shp file : shape %d : nPoints = %d",
1913 nRequiredSize = 48 + nPoints * 16;
1916 nRequiredSize += 16 + nPoints * 8;
1918 if (nRequiredSize > nEntitySize)
1920 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1921 "Corrupted .shp file : shape %d : nPoints = %d, nEntitySize = %d",
1922 hEntity, nPoints, nEntitySize);
1929 psShape->
padfX = (
double *) calloc(nPoints,
sizeof(
double));
1930 psShape->
padfY = (
double *) calloc(nPoints,
sizeof(
double));
1931 psShape->
padfZ = (
double *) calloc(nPoints,
sizeof(
double));
1932 psShape->
padfM = (
double *) calloc(nPoints,
sizeof(
double));
1934 if (psShape->
padfX == NULL ||
1935 psShape->
padfY == NULL ||
1936 psShape->
padfZ == NULL ||
1937 psShape->
padfM == NULL)
1939 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1940 "Not enough memory to allocate requested memory (nPoints=%d) for shape %d. " 1941 "Probably broken SHP file", hEntity, nPoints );
1947 for( i = 0; i < nPoints; i++ )
1949 memcpy(psShape->
padfX+i, psSHP->
pabyRec + 48 + 16 * i, 8 );
1950 memcpy(psShape->
padfY+i, psSHP->
pabyRec + 48 + 16 * i + 8, 8 );
1956 nOffset = 48 + 16*nPoints;
1977 memcpy( &(psShape->
dfZMax), psSHP->
pabyRec + nOffset + 8, 8 );
1982 for( i = 0; i < nPoints; i++ )
1984 memcpy( psShape->
padfZ + i,
1985 psSHP->
pabyRec + nOffset + 16 + i*8, 8 );
1989 nOffset += 16 + 8*nPoints;
1998 if( nEntitySize >= nOffset + 16 + 8*nPoints )
2001 memcpy( &(psShape->
dfMMax), psSHP->
pabyRec + nOffset + 8, 8 );
2006 for( i = 0; i < nPoints; i++ )
2008 memcpy( psShape->
padfM + i,
2009 psSHP->
pabyRec + nOffset + 16 + i*8, 8 );
2026 psShape->
padfX = (
double *) calloc(1,
sizeof(
double));
2027 psShape->
padfY = (
double *) calloc(1,
sizeof(
double));
2028 psShape->
padfZ = (
double *) calloc(1,
sizeof(
double));
2029 psShape->
padfM = (
double *) calloc(1,
sizeof(
double));
2033 snprintf(szErrorMsg,
sizeof(szErrorMsg),
2034 "Corrupted .shp file : shape %d : nEntitySize = %d",
2035 hEntity, nEntitySize);
2066 if( nEntitySize >= nOffset + 8 )
2110 return "MultiPoint";
2122 return "MultiPointZ";
2134 return "MultiPointM";
2137 return "MultiPatch";
2140 return "UnknownShapeType";
2155 return "TriangleStrip";
2158 return "TriangleFan";
2173 return "UnknownPartType";
2185 if( psShape == NULL )
2188 if( psShape->
padfX != NULL )
2190 if( psShape->
padfY != NULL )
2192 if( psShape->
padfZ != NULL )
2194 if( psShape->
padfM != NULL )
2216 int iOpRing, bAltered = 0;
2232 for( iOpRing = 0; iOpRing < psObject->
nParts; iOpRing++ )
2234 int bInner, iVert, nVertCount, nVertStart, iCheckRing;
2235 double dfSum, dfTestX, dfTestY;
2255 for( iCheckRing = 0; iCheckRing < psObject->
nParts; iCheckRing++ )
2259 if( iCheckRing == iOpRing )
2264 if( iCheckRing == psObject->
nParts-1 )
2271 for( iEdge = 0; iEdge < nVertCount; iEdge++ )
2275 if( iEdge < nVertCount-1 )
2284 if ( ( psObject->
padfY[iEdge+nVertStart] < dfTestY
2285 && dfTestY <= psObject->padfY[iNext+nVertStart] )
2286 || ( psObject->
padfY[iNext+nVertStart] < dfTestY
2287 && dfTestY <= psObject->
padfY[iEdge+nVertStart] ) )
2292 double const intersect =
2293 ( psObject->
padfX[iEdge+nVertStart]
2294 + ( dfTestY - psObject->
padfY[iEdge+nVertStart] )
2295 / ( psObject->
padfY[iNext+nVertStart] - psObject->
padfY[iEdge+nVertStart] )
2296 * ( psObject->
padfX[iNext+nVertStart] - psObject->
padfX[iEdge+nVertStart] ) );
2298 if (intersect < dfTestX)
2312 if( iOpRing == psObject->
nParts-1 )
2321 dfSum = psObject->
padfX[nVertStart] * (psObject->
padfY[nVertStart+1] - psObject->
padfY[nVertStart+nVertCount-1]);
2322 for( iVert = nVertStart + 1; iVert < nVertStart+nVertCount-1; iVert++ )
2324 dfSum += psObject->
padfX[iVert] * (psObject->
padfY[iVert+1] - psObject->
padfY[iVert-1]);
2327 dfSum += psObject->
padfX[iVert] * (psObject->
padfY[nVertStart] - psObject->
padfY[iVert-1]);
2332 if( (dfSum < 0.0 && bInner) || (dfSum > 0.0 && !bInner) )
2337 for( i = 0; i < nVertCount/2; i++ )
2342 dfSaved = psObject->
padfX[nVertStart+i];
2343 psObject->
padfX[nVertStart+i] =
2344 psObject->
padfX[nVertStart+nVertCount-i-1];
2345 psObject->
padfX[nVertStart+nVertCount-i-1] = dfSaved;
2348 dfSaved = psObject->
padfY[nVertStart+i];
2349 psObject->
padfY[nVertStart+i] =
2350 psObject->
padfY[nVertStart+nVertCount-i-1];
2351 psObject->
padfY[nVertStart+nVertCount-i-1] = dfSaved;
2354 if( psObject->
padfZ )
2356 dfSaved = psObject->
padfZ[nVertStart+i];
2357 psObject->
padfZ[nVertStart+i] =
2358 psObject->
padfZ[nVertStart+nVertCount-i-1];
2359 psObject->
padfZ[nVertStart+nVertCount-i-1] = dfSaved;
2363 if( psObject->
padfM )
2365 dfSaved = psObject->
padfM[nVertStart+i];
2366 psObject->
padfM[nVertStart+i] =
2367 psObject->
padfM[nVertStart+nVertCount-i-1];
2368 psObject->
padfM[nVertStart+nVertCount-i-1] = dfSaved;
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)
void SHPAPI_CALL SHPGetInfo(SHPHandle psSHP, int *pnEntities, int *pnShapeType, double *padfMinBound, double *padfMaxBound)
static void * SfRealloc(void *pMem, int nNewSize)
void SHPAPI_CALL SHPDestroyObject(SHPObject *psShape)
int(* FFlush)(SAFile file)
const char SHPAPI_CALL1 * SHPPartTypeName(int nPartType){ switch(nPartType
#define ByteCopy(a, b, c)
#define DISABLE_MULTIPATCH_MEASURE
SHPHandle SHPAPI_CALL SHPCreate(const char *pszLayer, int nShapeType)
int(* FClose)(SAFile file)
#define SHP_CVSID(string)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
const char SHPAPI_CALL1 * SHPTypeName(int nSHPType){ switch(nSHPType
unsigned int * panRecOffset
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)
void SHPAPI_CALL SHPComputeExtents(SHPObject *psObject)
int SHPAPI_CALL SHPRewindObject(SHPHandle hSHP, SHPObject *psObject)
int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject *psObject)
unsigned int * panRecSize
static void _SHPSetBounds(uchar *pabyRec, SHPObject *psShape)
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)
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)
SAFile(* FOpen)(const char *filename, const char *access)
SHPObject SHPAPI_CALL1 * SHPReadObject(SHPHandle psSHP, int hEntity){ int nEntitySize, nRequiredSize;SHPObject *psShape;char szErrorMsg[128];if(hEntity< 0||hEntity >=psSHP->nRecords) return(NULL
SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType, SAHooks *psHooks)
static void SwapWord(int length, void *wordP)
void(* Error)(const char *message)
SAOffset(* FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
void SASetupDefaultHooks(SAHooks *psHooks)
void SHPAPI_CALL SHPClose(SHPHandle psSHP)