PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ SHPReadObject()

SHPObject SHPAPI_CALL1* SHPReadObject ( SHPHandle  hSHP,
int  iShape 
)

Definition at line 1830 of file shpopen.c.

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