PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ SHPReadObject()

SHPObject SHPAPI_CALL1* SHPReadObject ( SHPHandle  hSHP,
int  iShape 
)

Definition at line 1832 of file shpopen.c.

1835 {
1836  int nEntitySize, nRequiredSize;
1837  SHPObject *psShape;
1838  char szErrorMsg[160];
1839  int nSHPType;
1840  int nBytesRead;
1841 
1842 /* -------------------------------------------------------------------- */
1843 /* Validate the record/entity number. */
1844 /* -------------------------------------------------------------------- */
1845  if( hEntity < 0 || hEntity >= psSHP->nRecords )
1846  return SHPLIB_NULLPTR;
1847 
1848 /* -------------------------------------------------------------------- */
1849 /* Read offset/length from SHX loading if necessary. */
1850 /* -------------------------------------------------------------------- */
1851  if( psSHP->panRecOffset[hEntity] == 0 && psSHP->fpSHX != SHPLIB_NULLPTR )
1852  {
1853  unsigned int nOffset, nLength;
1854 
1855  if( psSHP->sHooks.FSeek( psSHP->fpSHX, 100 + 8 * hEntity, 0 ) != 0 ||
1856  psSHP->sHooks.FRead( &nOffset, 1, 4, psSHP->fpSHX ) != 4 ||
1857  psSHP->sHooks.FRead( &nLength, 1, 4, psSHP->fpSHX ) != 4 )
1858  {
1859  char str[128];
1860  snprintf( str, sizeof(str),
1861  "Error in fseek()/fread() reading object from .shx file at offset %d",
1862  100 + 8 * hEntity);
1863  str[sizeof(str)-1] = '\0';
1864 
1865  psSHP->sHooks.Error( str );
1866  return SHPLIB_NULLPTR;
1867  }
1868  if( !bBigEndian ) SwapWord( 4, &nOffset );
1869  if( !bBigEndian ) SwapWord( 4, &nLength );
1870 
1871  if( nOffset > STATIC_CAST(unsigned int, INT_MAX) )
1872  {
1873  char str[128];
1874  snprintf( str, sizeof(str),
1875  "Invalid offset for entity %d", hEntity);
1876  str[sizeof(str)-1] = '\0';
1877 
1878  psSHP->sHooks.Error( str );
1879  return SHPLIB_NULLPTR;
1880  }
1881  if( nLength > STATIC_CAST(unsigned int, INT_MAX / 2 - 4) )
1882  {
1883  char str[128];
1884  snprintf( str, sizeof(str),
1885  "Invalid length for entity %d", hEntity);
1886  str[sizeof(str)-1] = '\0';
1887 
1888  psSHP->sHooks.Error( str );
1889  return SHPLIB_NULLPTR;
1890  }
1891 
1892  psSHP->panRecOffset[hEntity] = nOffset*2;
1893  psSHP->panRecSize[hEntity] = nLength*2;
1894  }
#define str(s)
static int bBigEndian
Definition: shpopen.c:93
else psShape
Definition: shpopen.c:2057
psObject nSHPType
Definition: shpopen.c:1211
nEntitySize
Definition: shpopen.c:1899
static void SwapWord(int length, void *wordP)
Definition: shpopen.c:110
#define STATIC_CAST(type, x)
Definition: shpopen.c:100
nBytesRead
Definition: shpopen.c:1984
#define SHPLIB_NULLPTR
Definition: shpopen.c:101

References bBigEndian, nBytesRead, nEntitySize, nSHPType, psShape, SHPLIB_NULLPTR, STATIC_CAST, str, and SwapWord().

Referenced by ShpLoaderGenerateSQLRowStatement(), and ShpLoaderOpenShape().

Here is the call graph for this function:
Here is the caller graph for this function: