@@ -85,12 +85,12 @@ public static function supportsDbase(): bool
85
85
}
86
86
87
87
/**
88
- * @param int $shapeType File shape type, should be same as all records
88
+ * @param ShapeType $shapeType File shape type, should be same as all records
89
89
* @param mixed[] $boundingBox File bounding box
90
90
* @param string|null $fileName File name
91
91
*/
92
92
public function __construct (
93
- public int $ shapeType ,
93
+ public ShapeType $ shapeType ,
94
94
public array $ boundingBox = [
95
95
'xmin ' => 0.0 ,
96
96
'ymin ' => 0.0 ,
@@ -374,7 +374,11 @@ private function loadHeaders(): bool
374
374
$ this ->readSHP (4 );
375
375
376
376
$ shapeType = Util::loadData ('V ' , $ this ->readSHP (4 ));
377
- $ this ->shapeType = $ shapeType === false ? -1 : (int ) $ shapeType ;
377
+ if ($ shapeType === false ) {
378
+ $ this ->shapeType = ShapeType::Unknown;
379
+ } else {
380
+ $ this ->shapeType = ShapeType::tryFrom ((int ) $ shapeType ) ?? ShapeType::Unknown;
381
+ }
378
382
379
383
$ this ->boundingBox = [];
380
384
$ this ->boundingBox ['xmin ' ] = Util::loadData ('d ' , $ this ->readSHP (8 ));
@@ -435,7 +439,7 @@ private function saveHeaders(): void
435
439
fwrite ($ this ->shpFile , pack ('NNNNNN ' , self ::MAGIC , 0 , 0 , 0 , 0 , 0 ));
436
440
fwrite ($ this ->shpFile , pack ('N ' , $ this ->fileLength ));
437
441
fwrite ($ this ->shpFile , pack ('V ' , 1000 ));
438
- fwrite ($ this ->shpFile , pack ('V ' , $ this ->shapeType ));
442
+ fwrite ($ this ->shpFile , pack ('V ' , $ this ->shapeType -> value ));
439
443
$ this ->saveBBox ($ this ->shpFile );
440
444
441
445
if ($ this ->shxFile === false ) {
@@ -445,7 +449,7 @@ private function saveHeaders(): void
445
449
fwrite ($ this ->shxFile , pack ('NNNNNN ' , self ::MAGIC , 0 , 0 , 0 , 0 , 0 ));
446
450
fwrite ($ this ->shxFile , pack ('N ' , 50 + 4 * count ($ this ->records )));
447
451
fwrite ($ this ->shxFile , pack ('V ' , 1000 ));
448
- fwrite ($ this ->shxFile , pack ('V ' , $ this ->shapeType ));
452
+ fwrite ($ this ->shxFile , pack ('V ' , $ this ->shapeType -> value ));
449
453
$ this ->saveBBox ($ this ->shxFile );
450
454
}
451
455
@@ -456,15 +460,15 @@ private function loadRecords(): bool
456
460
{
457
461
/* Need to start at offset 100 */
458
462
while (! $ this ->eofSHP ()) {
459
- $ record = new ShapeRecord (- 1 );
463
+ $ record = new ShapeRecord (ShapeType::Unknown );
460
464
$ record ->loadFromFile ($ this , $ this ->dbfFile );
461
465
if ($ record ->lastError !== '' ) {
462
466
$ this ->setError ($ record ->lastError );
463
467
464
468
return false ;
465
469
}
466
470
467
- if (($ record ->shapeType === - 1 ) && $ this ->eofSHP ()) {
471
+ if (($ record ->shapeType === ShapeType::Unknown ) && $ this ->eofSHP ()) {
468
472
break ;
469
473
}
470
474
0 commit comments