1670 int32 nPoints, nParts;
1675 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1676 "Corrupted .shp file : shape %d : nEntitySize = %d",
1678 psSHP->sHooks.Error( szErrorMsg );
1685 memcpy( &(
psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8 );
1686 memcpy( &(
psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
1687 memcpy( &(
psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
1688 memcpy( &(
psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
1699 memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );
1700 memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );
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);
1710 psSHP->sHooks.Error( szErrorMsg );
1718 nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
1723 nRequiredSize += 16 + 8 * nPoints;
1727 nRequiredSize += 4 * nParts;
1731 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1732 "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d, nEntitySize=%d.",
1734 psSHP->sHooks.Error( szErrorMsg );
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));
1746 psShape->panPartStart = (
int *) calloc(nParts,
sizeof(
int));
1747 psShape->panPartType = (
int *) calloc(nParts,
sizeof(
int));
1753 psShape->panPartStart == 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 );
1759 psSHP->sHooks.Error( szErrorMsg );
1764 for( i = 0; i < nParts; i++ )
1770 memcpy(
psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );
1771 for( i = 0; i < nParts; i++ )
1776 if (
psShape->panPartStart[i] < 0
1780 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1781 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
1783 psSHP->sHooks.Error( szErrorMsg );
1787 if (i > 0 &&
psShape->panPartStart[i] <=
psShape->panPartStart[i-1])
1789 snprintf(szErrorMsg,
sizeof(szErrorMsg),
1790 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
1791 hEntity, i,
psShape->panPartStart[i], i - 1,
psShape->panPartStart[i - 1]);
1792 psSHP->sHooks.Error( szErrorMsg );
1798 nOffset = 44 + 8 + 4*nParts;
1805 memcpy(
psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );
1806 for( i = 0; i < nParts; i++ )
1811 nOffset += 4*nParts;
1817 for( i = 0; i < nPoints; i++ )
1820 psSHP->pabyRec + nOffset + i * 16,
1824 psSHP->pabyRec + nOffset + i * 16 + 8,
1831 nOffset += 16*nPoints;
1840 memcpy( &(
psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
1841 memcpy( &(
psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
1846 for( i = 0; i < nPoints; i++ )
1849 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
1853 nOffset += 16 + 8*nPoints;
1864 memcpy( &(
psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
1865 memcpy( &(
psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
1870 for( i = 0; i < nPoints; i++ )
1873 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
static void SwapWord(int length, void *wordP)
void SHPAPI_CALL SHPDestroyObject(SHPObject *psShape)