** msSHPReadPoint() - Reads a single point from a POINT shape file. */
| 1012 | ** msSHPReadPoint() - Reads a single point from a POINT shape file. |
| 1013 | */ |
| 1014 | int msSHPReadPoint( SHPHandle psSHP, int hEntity, pointObj *point ) |
| 1015 | { |
| 1016 | int nEntitySize; |
| 1017 | |
| 1018 | /* -------------------------------------------------------------------- */ |
| 1019 | /* Only valid for point shapefiles */ |
| 1020 | /* -------------------------------------------------------------------- */ |
| 1021 | if( psSHP->nShapeType != SHP_POINT ) { |
| 1022 | msSetError(MS_SHPERR, "msSHPReadPoint only operates on point shapefiles.", "msSHPReadPoint()"); |
| 1023 | return(MS_FAILURE); |
| 1024 | } |
| 1025 | |
| 1026 | /* -------------------------------------------------------------------- */ |
| 1027 | /* Validate the record/entity number. */ |
| 1028 | /* -------------------------------------------------------------------- */ |
| 1029 | if( hEntity < 0 || hEntity >= psSHP->nRecords ) { |
| 1030 | msSetError(MS_SHPERR, "Record index out of bounds.", "msSHPReadPoint()"); |
| 1031 | return(MS_FAILURE); |
| 1032 | } |
| 1033 | |
| 1034 | nEntitySize = msSHXReadSize( psSHP, hEntity) + 8; |
| 1035 | |
| 1036 | if( msSHXReadSize( psSHP, hEntity) == 4 ) { |
| 1037 | msSetError(MS_SHPERR, "NULL feature encountered.", "msSHPReadPoint()"); |
| 1038 | return(MS_FAILURE); |
| 1039 | } |
| 1040 | else if ( nEntitySize < 28 ) { |
| 1041 | msSetError(MS_SHPERR, "Corrupted feature encountered. hEntity=%d, nEntitySize=%d", "msSHPReadPoint()", |
| 1042 | hEntity, nEntitySize); |
| 1043 | return(MS_FAILURE); |
| 1044 | } |
| 1045 | |
| 1046 | if (msSHPReadAllocateBuffer(psSHP, hEntity, "msSHPReadPoint()") == MS_FAILURE) |
| 1047 | { |
| 1048 | return MS_FAILURE; |
| 1049 | } |
| 1050 | |
| 1051 | /* -------------------------------------------------------------------- */ |
| 1052 | /* Read the record. */ |
| 1053 | /* -------------------------------------------------------------------- */ |
| 1054 | fseek( psSHP->fpSHP, msSHXReadOffset( psSHP, hEntity), 0 ); |
| 1055 | fread( psSHP->pabyRec, nEntitySize, 1, psSHP->fpSHP ); |
| 1056 | |
| 1057 | memcpy( &(point->x), psSHP->pabyRec + 12, 8 ); |
| 1058 | memcpy( &(point->y), psSHP->pabyRec + 20, 8 ); |
| 1059 | |
| 1060 | if( bBigEndian ) { |
| 1061 | SwapWord( 8, &(point->x)); |
| 1062 | SwapWord( 8, &(point->y)); |
| 1063 | } |
| 1064 | |
| 1065 | return(MS_SUCCESS); |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | ** msSHXLoadPage() |
no test coverage detected