MCPcopy Index your code
hub / github.com/MapServer/MapServer / msSHPReadShape

Function msSHPReadShape

mapshape.c:1187–1571  ·  view source on GitHub ↗

** msSHPReadShape() - Reads the vertices for one shape from a shape file. */

Source from the content-addressed store, hash-verified

1185** msSHPReadShape() - Reads the vertices for one shape from a shape file.
1186*/
1187void 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 ) {

Callers 7

mainFunction · 0.85
msTiledSHPNextShapeFunction · 0.85
msTiledSHPGetShapeFunction · 0.85
msSHPLayerNextShapeFunction · 0.85
msSHPLayerGetShapeFunction · 0.85
shapefileObj_getFunction · 0.85

Calls 8

msInitShapeFunction · 0.85
msSHXReadSizeFunction · 0.85
msSHPReadAllocateBufferFunction · 0.85
msSHXReadOffsetFunction · 0.85
msSetErrorFunction · 0.85
msSmallMallocFunction · 0.85
SwapWordFunction · 0.70
SfReallocFunction · 0.70

Tested by

no test coverage detected