PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ if() [9/9]

Definition at line 1883 of file shpopen.c.

References SHPObject::bMeasureIsUsed, SHPObject::dfMMax, SHPObject::dfMMin, SHPObject::dfXMax, SHPObject::dfXMin, SHPObject::dfYMax, SHPObject::dfYMin, SHPObject::dfZMax, SHPObject::dfZMin, SAHooks::Error, SHPObject::nSHPType, SHPObject::nVertices, SHPInfo::pabyRec, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, SHPInfo::sHooks, SHPAPI_CALL1, SHPDestroyObject(), SHPT_MULTIPOINTZ, SHPT_POINT, SHPT_POINTM, SHPT_POINTZ, SwapWord(), and TRUE.

1886  {
1887  int32 nPoints;
1888  int i, nOffset;
1889 
1890  if ( 44 + 4 > nEntitySize )
1891  {
1892  snprintf(szErrorMsg, sizeof(szErrorMsg),
1893  "Corrupted .shp file : shape %d : nEntitySize = %d",
1894  hEntity, nEntitySize);
1895  psSHP->sHooks.Error( szErrorMsg );
1897  return NULL;
1898  }
1899  memcpy( &nPoints, psSHP->pabyRec + 44, 4 );
1900 
1901  if( bBigEndian ) SwapWord( 4, &nPoints );
1902 
1903  if (nPoints > 50 * 1000 * 1000)
1904  {
1905  snprintf(szErrorMsg, sizeof(szErrorMsg),
1906  "Corrupted .shp file : shape %d : nPoints = %d",
1907  hEntity, nPoints);
1908  psSHP->sHooks.Error( szErrorMsg );
1910  return NULL;
1911  }
1912 
1913  nRequiredSize = 48 + nPoints * 16;
1914  if( psShape->nSHPType == SHPT_MULTIPOINTZ )
1915  {
1916  nRequiredSize += 16 + nPoints * 8;
1917  }
1918  if (nRequiredSize > nEntitySize)
1919  {
1920  snprintf(szErrorMsg, sizeof(szErrorMsg),
1921  "Corrupted .shp file : shape %d : nPoints = %d, nEntitySize = %d",
1922  hEntity, nPoints, nEntitySize);
1923  psSHP->sHooks.Error( szErrorMsg );
1925  return NULL;
1926  }
1927 
1928  psShape->nVertices = nPoints;
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));
1933 
1934  if (psShape->padfX == NULL ||
1935  psShape->padfY == NULL ||
1936  psShape->padfZ == NULL ||
1937  psShape->padfM == NULL)
1938  {
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 );
1942  psSHP->sHooks.Error( szErrorMsg );
1944  return NULL;
1945  }
1946 
1947  for( i = 0; i < nPoints; i++ )
1948  {
1949  memcpy(psShape->padfX+i, psSHP->pabyRec + 48 + 16 * i, 8 );
1950  memcpy(psShape->padfY+i, psSHP->pabyRec + 48 + 16 * i + 8, 8 );
1951 
1952  if( bBigEndian ) SwapWord( 8, psShape->padfX + i );
1953  if( bBigEndian ) SwapWord( 8, psShape->padfY + i );
1954  }
1955 
1956  nOffset = 48 + 16*nPoints;
1957 
1958 /* -------------------------------------------------------------------- */
1959 /* Get the X/Y bounds. */
1960 /* -------------------------------------------------------------------- */
1961  memcpy( &(psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8 );
1962  memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
1963  memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
1964  memcpy( &(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
1965 
1966  if( bBigEndian ) SwapWord( 8, &(psShape->dfXMin) );
1967  if( bBigEndian ) SwapWord( 8, &(psShape->dfYMin) );
1968  if( bBigEndian ) SwapWord( 8, &(psShape->dfXMax) );
1969  if( bBigEndian ) SwapWord( 8, &(psShape->dfYMax) );
1970 
1971 /* -------------------------------------------------------------------- */
1972 /* If we have a Z coordinate, collect that now. */
1973 /* -------------------------------------------------------------------- */
1974  if( psShape->nSHPType == SHPT_MULTIPOINTZ )
1975  {
1976  memcpy( &(psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
1977  memcpy( &(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
1978 
1979  if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );
1980  if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );
1981 
1982  for( i = 0; i < nPoints; i++ )
1983  {
1984  memcpy( psShape->padfZ + i,
1985  psSHP->pabyRec + nOffset + 16 + i*8, 8 );
1986  if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );
1987  }
1988 
1989  nOffset += 16 + 8*nPoints;
1990  }
1991 
1992 /* -------------------------------------------------------------------- */
1993 /* If we have a M measure value, then read it now. We assume */
1994 /* that the measure can be present for any shape if the size is */
1995 /* big enough, but really it will only occur for the Z shapes */
1996 /* (options), and the M shapes. */
1997 /* -------------------------------------------------------------------- */
1998  if( nEntitySize >= nOffset + 16 + 8*nPoints )
1999  {
2000  memcpy( &(psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
2001  memcpy( &(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
2002 
2003  if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );
2004  if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );
2005 
2006  for( i = 0; i < nPoints; i++ )
2007  {
2008  memcpy( psShape->padfM + i,
2009  psSHP->pabyRec + nOffset + 16 + i*8, 8 );
2010  if( bBigEndian ) SwapWord( 8, psShape->padfM + i );
2011  }
2012  psShape->bMeasureIsUsed = TRUE;
2013  }
2014  }
unsigned int int32
Definition: shpopen.c:273
void SHPAPI_CALL SHPDestroyObject(SHPObject *psShape)
Definition: shpopen.c:2182
#define SHPT_MULTIPOINTZ
Definition: shapefil.h:314
psShape
Definition: shpopen.c:1643
static int bBigEndian
Definition: shpopen.c:293
nEntitySize
Definition: shpopen.c:1579
#define TRUE
Definition: shpopen.c:278
static void SwapWord(int length, void *wordP)
Definition: shpopen.c:302
Here is the call graph for this function: