PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ SHPReadObject()

SHPObject SHPAPI_CALL1 * SHPReadObject ( SHPHandle  hSHP,
int  iShape 
)

Definition at line 1841 of file shpopen.c.

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