** msSHPReadShape() - Reads the vertices for one shape from a shape file. */
| 1185 | ** msSHPReadShape() - Reads the vertices for one shape from a shape file. |
| 1186 | */ |
| 1187 | void msSHPReadShape( SHPHandle psSHP, int hEntity, shapeObj *shape ) |
| 1188 | { |
| 1189 | int i, j, k; |
| 1190 | #ifdef USE_POINT_Z_M |
| 1191 | int nOffset = 0; |
| 1192 | #endif |
| 1193 | int nEntitySize, nRequiredSize; |
| 1194 | |
| 1195 | msInitShape(shape); /* initialize the shape */ |
| 1196 | |
| 1197 | /* -------------------------------------------------------------------- */ |
| 1198 | /* Validate the record/entity number. */ |
| 1199 | /* -------------------------------------------------------------------- */ |
| 1200 | if( hEntity < 0 || hEntity >= psSHP->nRecords ) |
| 1201 | return; |
| 1202 | |
| 1203 | if( msSHXReadSize(psSHP, hEntity) == 4 ) { |
| 1204 | shape->type = MS_SHAPE_NULL; |
| 1205 | return; |
| 1206 | } |
| 1207 | |
| 1208 | nEntitySize = msSHXReadSize(psSHP, hEntity) + 8; |
| 1209 | if (msSHPReadAllocateBuffer(psSHP, hEntity, "msSHPReadShape()") == MS_FAILURE) |
| 1210 | { |
| 1211 | shape->type = MS_SHAPE_NULL; |
| 1212 | return; |
| 1213 | } |
| 1214 | |
| 1215 | /* -------------------------------------------------------------------- */ |
| 1216 | /* Read the record. */ |
| 1217 | /* -------------------------------------------------------------------- */ |
| 1218 | fseek( psSHP->fpSHP, msSHXReadOffset(psSHP, hEntity), 0 ); |
| 1219 | fread( psSHP->pabyRec, nEntitySize, 1, psSHP->fpSHP ); |
| 1220 | |
| 1221 | /* -------------------------------------------------------------------- */ |
| 1222 | /* Extract vertices for a Polygon or Arc. */ |
| 1223 | /* -------------------------------------------------------------------- */ |
| 1224 | if( psSHP->nShapeType == SHP_POLYGON || psSHP->nShapeType == SHP_ARC || |
| 1225 | psSHP->nShapeType == SHP_POLYGONM || psSHP->nShapeType == SHP_ARCM || |
| 1226 | psSHP->nShapeType == SHP_POLYGONZ || psSHP->nShapeType == SHP_ARCZ) |
| 1227 | { |
| 1228 | ms_int32 nPoints, nParts; |
| 1229 | |
| 1230 | if (nEntitySize < 40 + 8 + 4) |
| 1231 | { |
| 1232 | shape->type = MS_SHAPE_NULL; |
| 1233 | msSetError(MS_SHPERR, "Corrupted feature encountered. hEntity = %d, nEntitySize=%d", "msSHPReadShape()", |
| 1234 | hEntity, nEntitySize); |
| 1235 | return; |
| 1236 | } |
| 1237 | |
| 1238 | /* copy the bounding box */ |
| 1239 | memcpy( &shape->bounds.minx, psSHP->pabyRec + 8 + 4, 8 ); |
| 1240 | memcpy( &shape->bounds.miny, psSHP->pabyRec + 8 + 12, 8 ); |
| 1241 | memcpy( &shape->bounds.maxx, psSHP->pabyRec + 8 + 20, 8 ); |
| 1242 | memcpy( &shape->bounds.maxy, psSHP->pabyRec + 8 + 28, 8 ); |
| 1243 | |
| 1244 | if( bBigEndian ) { |
no test coverage detected