@@ -79,19 +79,19 @@ public function loadFromFile(ShapeFile $shapeFile, $dbfFile): void
7979 }
8080
8181 match ($ this ->shapeType ) {
82- 0 => $ this ->loadNullRecord (),
83- 1 => $ this ->loadPointRecord (),
84- 21 => $ this ->loadPointMRecord (),
85- 11 => $ this ->loadPointZRecord (),
86- 3 => $ this ->loadPolyLineRecord (),
87- 23 => $ this ->loadPolyLineMRecord (),
88- 13 => $ this ->loadPolyLineZRecord (),
89- 5 => $ this ->loadPolygonRecord (),
90- 25 => $ this ->loadPolygonMRecord (),
91- 15 => $ this ->loadPolygonZRecord (),
92- 8 => $ this ->loadMultiPointRecord (),
93- 28 => $ this ->loadMultiPointMRecord (),
94- 18 => $ this ->loadMultiPointZRecord (),
82+ ShapeType:: NULL => $ this ->loadNullRecord (),
83+ ShapeType:: POINT => $ this ->loadPointRecord (),
84+ ShapeType:: POINT_M => $ this ->loadPointMRecord (),
85+ ShapeType:: POINT_Z => $ this ->loadPointZRecord (),
86+ ShapeType:: POLY_LINE => $ this ->loadPolyLineRecord (),
87+ ShapeType:: POLY_LINE_M => $ this ->loadPolyLineMRecord (),
88+ ShapeType:: POLY_LINE_Z => $ this ->loadPolyLineZRecord (),
89+ ShapeType:: POLYGON => $ this ->loadPolygonRecord (),
90+ ShapeType:: POLYGON_M => $ this ->loadPolygonMRecord (),
91+ ShapeType:: POLYGON_Z => $ this ->loadPolygonZRecord (),
92+ ShapeType:: MULTI_POINT => $ this ->loadMultiPointRecord (),
93+ ShapeType:: MULTI_POINT_M => $ this ->loadMultiPointMRecord (),
94+ ShapeType:: MULTI_POINT_Z => $ this ->loadMultiPointZRecord (),
9595 default => $ this ->setError (sprintf ('The Shape Type "%s" is not supported. ' , $ this ->shapeType )),
9696 };
9797
@@ -126,19 +126,19 @@ public function saveToFile($shpFile, $dbfFile, int $recordNumber): void
126126 $ this ->saveHeaders ();
127127
128128 match ($ this ->shapeType ) {
129- 0 => null , // Nothing to save
130- 1 => $ this ->savePointRecord (),
131- 21 => $ this ->savePointMRecord (),
132- 11 => $ this ->savePointZRecord (),
133- 3 => $ this ->savePolyLineRecord (),
134- 23 => $ this ->savePolyLineMRecord (),
135- 13 => $ this ->savePolyLineZRecord (),
136- 5 => $ this ->savePolygonRecord (),
137- 25 => $ this ->savePolygonMRecord (),
138- 15 => $ this ->savePolygonZRecord (),
139- 8 => $ this ->saveMultiPointRecord (),
140- 28 => $ this ->saveMultiPointMRecord (),
141- 18 => $ this ->saveMultiPointZRecord (),
129+ ShapeType:: NULL => null , // Nothing to save
130+ ShapeType:: POINT => $ this ->savePointRecord (),
131+ ShapeType:: POINT_M => $ this ->savePointMRecord (),
132+ ShapeType:: POINT_Z => $ this ->savePointZRecord (),
133+ ShapeType:: POLY_LINE => $ this ->savePolyLineRecord (),
134+ ShapeType:: POLY_LINE_M => $ this ->savePolyLineMRecord (),
135+ ShapeType:: POLY_LINE_Z => $ this ->savePolyLineZRecord (),
136+ ShapeType:: POLYGON => $ this ->savePolygonRecord (),
137+ ShapeType:: POLYGON_M => $ this ->savePolygonMRecord (),
138+ ShapeType:: POLYGON_Z => $ this ->savePolygonZRecord (),
139+ ShapeType:: MULTI_POINT => $ this ->saveMultiPointRecord (),
140+ ShapeType:: MULTI_POINT_M => $ this ->saveMultiPointMRecord (),
141+ ShapeType:: MULTI_POINT_Z => $ this ->saveMultiPointZRecord (),
142142 default => $ this ->setError (sprintf ('The Shape Type "%s" is not supported. ' , $ this ->shapeType )),
143143 };
144144
@@ -584,12 +584,12 @@ private function adjustBBox(array $point): void
584584 */
585585 private function adjustPoint (array $ point ): array
586586 {
587- $ type = $ this ->shapeType / 10 ;
588- if ($ type >= 2 ) {
587+ if (in_array ($ this ->shapeType , ShapeType::MEASURED_TYPES , true )) {
589588 $ point ['m ' ] ??= 0.0 ;
590- } elseif ($ type >= 1 ) {
589+ }
590+
591+ if (in_array ($ this ->shapeType , ShapeType::TYPES_WITH_Z , true )) {
591592 $ point ['z ' ] ??= 0.0 ;
592- $ point ['m ' ] ??= 0.0 ;
593593 }
594594
595595 return $ point ;
@@ -605,30 +605,30 @@ public function addPoint(array $point, int $partIndex = 0): void
605605 {
606606 $ point = $ this ->adjustPoint ($ point );
607607 switch ($ this ->shapeType ) {
608- case 0 :
608+ case ShapeType:: NULL :
609609 //Don't add anything
610610 return ;
611611
612- case 1 :
613- case 11 :
614- case 21 :
612+ case ShapeType:: POINT :
613+ case ShapeType:: POINT_Z :
614+ case ShapeType:: POINT_M :
615615 //Substitutes the value of the current point
616616 $ this ->shpData = $ point ;
617617 break ;
618- case 3 :
619- case 5 :
620- case 13 :
621- case 15 :
622- case 23 :
623- case 25 :
618+ case ShapeType:: POLY_LINE :
619+ case ShapeType:: POLYGON :
620+ case ShapeType:: POLY_LINE_Z :
621+ case ShapeType:: POLYGON_Z :
622+ case ShapeType:: POLY_LINE_M :
623+ case ShapeType:: POLYGON_M :
624624 //Adds a new point to the selected part
625625 $ this ->shpData ['parts ' ][$ partIndex ]['points ' ][] = $ point ;
626626 $ this ->shpData ['numparts ' ] = count ($ this ->shpData ['parts ' ]);
627627 $ this ->shpData ['numpoints ' ] = 1 + ($ this ->shpData ['numpoints ' ] ?? 0 );
628628 break ;
629- case 8 :
630- case 18 :
631- case 28 :
629+ case ShapeType:: MULTI_POINT :
630+ case ShapeType:: MULTI_POINT_Z :
631+ case ShapeType:: MULTI_POINT_M :
632632 //Adds a new point
633633 $ this ->shpData ['points ' ][] = $ point ;
634634 $ this ->shpData ['numpoints ' ] = 1 + ($ this ->shpData ['numpoints ' ] ?? 0 );
@@ -651,30 +651,30 @@ public function addPoint(array $point, int $partIndex = 0): void
651651 public function deletePoint (int $ pointIndex = 0 , int $ partIndex = 0 ): void
652652 {
653653 switch ($ this ->shapeType ) {
654- case 0 :
654+ case ShapeType:: NULL :
655655 //Don't delete anything
656656 break ;
657- case 1 :
658- case 11 :
659- case 21 :
657+ case ShapeType:: POINT :
658+ case ShapeType:: POINT_Z :
659+ case ShapeType:: POINT_M :
660660 //Sets the value of the point to zero
661661 $ this ->shpData ['x ' ] = 0.0 ;
662662 $ this ->shpData ['y ' ] = 0.0 ;
663- if (in_array ($ this ->shapeType , [11 , 21 ] )) {
663+ if (in_array ($ this ->shapeType , [ShapeType:: POINT_Z , ShapeType:: POINT_M ], true )) {
664664 $ this ->shpData ['m ' ] = 0.0 ;
665665 }
666666
667- if ($ this ->shapeType === 11 ) {
667+ if ($ this ->shapeType === ShapeType:: POINT_Z ) {
668668 $ this ->shpData ['z ' ] = 0.0 ;
669669 }
670670
671671 break ;
672- case 3 :
673- case 5 :
674- case 13 :
675- case 15 :
676- case 23 :
677- case 25 :
672+ case ShapeType:: POLY_LINE :
673+ case ShapeType:: POLYGON :
674+ case ShapeType:: POLY_LINE_Z :
675+ case ShapeType:: POLYGON_Z :
676+ case ShapeType:: POLY_LINE_M :
677+ case ShapeType:: POLYGON_M :
678678 //Deletes the point from the selected part, if exists
679679 if (
680680 isset ($ this ->shpData ['parts ' ][$ partIndex ])
@@ -694,9 +694,9 @@ public function deletePoint(int $pointIndex = 0, int $partIndex = 0): void
694694 }
695695
696696 break ;
697- case 8 :
698- case 18 :
699- case 28 :
697+ case ShapeType:: MULTI_POINT :
698+ case ShapeType:: MULTI_POINT_Z :
699+ case ShapeType:: MULTI_POINT_M :
700700 //Deletes the point, if exists
701701 if (isset ($ this ->shpData ['points ' ][$ pointIndex ])) {
702702 $ count = count ($ this ->shpData ['points ' ]) - 1 ;
@@ -724,52 +724,52 @@ public function getContentLength(): int|null
724724 // The content length for a record is the length of the record contents section measured in 16-bit words.
725725 // one coordinate makes 4 16-bit words (64 bit double)
726726 switch ($ this ->shapeType ) {
727- case 0 :
727+ case ShapeType:: NULL :
728728 $ result = 0 ;
729729 break ;
730- case 1 :
730+ case ShapeType:: POINT :
731731 $ result = 10 ;
732732 break ;
733- case 21 :
733+ case ShapeType:: POINT_M :
734734 $ result = 10 + 4 ;
735735 break ;
736- case 11 :
736+ case ShapeType:: POINT_Z :
737737 $ result = 10 + 8 ;
738738 break ;
739- case 3 :
740- case 5 :
739+ case ShapeType:: POLY_LINE :
740+ case ShapeType:: POLYGON :
741741 $ count = count ($ this ->shpData ['parts ' ]);
742742 $ result = 22 + 2 * $ count ;
743743 for ($ i = 0 ; $ i < $ count ; ++$ i ) {
744744 $ result += 8 * count ($ this ->shpData ['parts ' ][$ i ]['points ' ]);
745745 }
746746
747747 break ;
748- case 23 :
749- case 25 :
748+ case ShapeType:: POLY_LINE_M :
749+ case ShapeType:: POLYGON_M :
750750 $ count = count ($ this ->shpData ['parts ' ]);
751751 $ result = 22 + (2 * 4 ) + 2 * $ count ;
752752 for ($ i = 0 ; $ i < $ count ; ++$ i ) {
753753 $ result += (8 + 4 ) * count ($ this ->shpData ['parts ' ][$ i ]['points ' ]);
754754 }
755755
756756 break ;
757- case 13 :
758- case 15 :
757+ case ShapeType:: POLY_LINE_Z :
758+ case ShapeType:: POLYGON_Z :
759759 $ count = count ($ this ->shpData ['parts ' ]);
760760 $ result = 22 + (4 * 4 ) + 2 * $ count ;
761761 for ($ i = 0 ; $ i < $ count ; ++$ i ) {
762762 $ result += (8 + 8 ) * count ($ this ->shpData ['parts ' ][$ i ]['points ' ]);
763763 }
764764
765765 break ;
766- case 8 :
766+ case ShapeType:: MULTI_POINT :
767767 $ result = 20 + 8 * count ($ this ->shpData ['points ' ]);
768768 break ;
769- case 28 :
769+ case ShapeType:: MULTI_POINT_M :
770770 $ result = 20 + (2 * 4 ) + (8 + 4 ) * count ($ this ->shpData ['points ' ]);
771771 break ;
772- case 18 :
772+ case ShapeType:: MULTI_POINT_Z :
773773 $ result = 20 + (4 * 4 ) + (8 + 8 ) * count ($ this ->shpData ['points ' ]);
774774 break ;
775775 default :
@@ -815,9 +815,11 @@ public function setError(string $error): void
815815
816816 /**
817817 * Returns shape name.
818+ *
819+ * @psalm-return non-empty-string
818820 */
819821 public function getShapeName (): string
820822 {
821- return Util:: nameShape ($ this ->shapeType );
823+ return ShapeType:: name ($ this ->shapeType );
822824 }
823825}
0 commit comments