PostGIS  2.1.10dev-r@@SVN_REVISION@@

Definition at line 1884 of file shpopen.c.

References SHPObject::bMeasureIsUsed, SHPObject::dfMMax, SHPObject::dfMMin, SHPObject::dfXMax, SHPObject::dfXMin, SHPObject::dfYMax, SHPObject::dfYMin, SHPObject::dfZMax, SHPObject::dfZMin, SHPObject::nSHPType, SHPObject::nVertices, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, SHPDestroyObject(), SHPT_MULTIPOINTZ, SwapWord(), and TRUE.

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

Here is the call graph for this function: