@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | function swap($binValue) { |
38 | 38 | $result = $binValue{strlen($binValue) - 1}; |
39 | - for($i = strlen($binValue) - 2; $i >= 0 ; $i--) { |
|
39 | + for ($i = strlen($binValue) - 2; $i >= 0; $i--) { |
|
40 | 40 | $result .= $binValue{$i}; |
41 | 41 | } |
42 | 42 | |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | function packDouble($value, $mode = 'LE') { |
47 | - $value = (double)$value; |
|
47 | + $value = (double) $value; |
|
48 | 48 | $bin = pack("d", $value); |
49 | 49 | |
50 | 50 | //We test if the conversion of an integer (1) is done as LE or BE by default |
51 | - switch (pack ('L', 1)) { |
|
52 | - case pack ('V', 1): //Little Endian |
|
51 | + switch (pack('L', 1)) { |
|
52 | + case pack('V', 1): //Little Endian |
|
53 | 53 | $result = ($mode == 'LE') ? $bin : swap($bin); |
54 | 54 | break; |
55 | - case pack ('N', 1): //Big Endian |
|
55 | + case pack('N', 1): //Big Endian |
|
56 | 56 | $result = ($mode == 'BE') ? $bin : swap($bin); |
57 | 57 | break; |
58 | 58 | default: //Some other thing, we just return false |
@@ -127,20 +127,20 @@ discard block |
||
127 | 127 | $this->records[] = $record; |
128 | 128 | $this->records[count($this->records) - 1]->recordNumber = count($this->records); |
129 | 129 | |
130 | - if ($this->boundingBox["xmin"]==0.0 || ($this->boundingBox["xmin"]>$record->SHPData["xmin"])) $this->boundingBox["xmin"] = $record->SHPData["xmin"]; |
|
131 | - if ($this->boundingBox["xmax"]==0.0 || ($this->boundingBox["xmax"]<$record->SHPData["xmax"])) $this->boundingBox["xmax"] = $record->SHPData["xmax"]; |
|
130 | + if ($this->boundingBox["xmin"] == 0.0 || ($this->boundingBox["xmin"] > $record->SHPData["xmin"])) $this->boundingBox["xmin"] = $record->SHPData["xmin"]; |
|
131 | + if ($this->boundingBox["xmax"] == 0.0 || ($this->boundingBox["xmax"] < $record->SHPData["xmax"])) $this->boundingBox["xmax"] = $record->SHPData["xmax"]; |
|
132 | 132 | |
133 | - if ($this->boundingBox["ymin"]==0.0 || ($this->boundingBox["ymin"]>$record->SHPData["ymin"])) $this->boundingBox["ymin"] = $record->SHPData["ymin"]; |
|
134 | - if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
|
133 | + if ($this->boundingBox["ymin"] == 0.0 || ($this->boundingBox["ymin"] > $record->SHPData["ymin"])) $this->boundingBox["ymin"] = $record->SHPData["ymin"]; |
|
134 | + if ($this->boundingBox["ymax"] == 0.0 || ($this->boundingBox["ymax"] < $record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"]; |
|
135 | 135 | |
136 | - if (in_array($this->shapeType,array(11,13,15,18,21,23,25,28))) { |
|
137 | - if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
138 | - if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
136 | + if (in_array($this->shapeType, array(11, 13, 15, 18, 21, 23, 25, 28))) { |
|
137 | + if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"] == 0.0 || ($this->boundingBox["mmin"] > $record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"]; |
|
138 | + if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"] == 0.0 || ($this->boundingBox["mmax"] < $record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"]; |
|
139 | 139 | } |
140 | 140 | |
141 | - if (in_array($this->shapeType,array(11,13,15,18))) { |
|
142 | - if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
143 | - if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
141 | + if (in_array($this->shapeType, array(11, 13, 15, 18))) { |
|
142 | + if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"] == 0.0 || ($this->boundingBox["zmin"] > $record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"]; |
|
143 | + if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"] == 0.0 || ($this->boundingBox["zmax"] < $record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"]; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return (count($this->records) - 1); |
@@ -251,23 +251,23 @@ discard block |
||
251 | 251 | fwrite($this->SHPFile, packDouble($this->boundingBox['ymin'])); |
252 | 252 | fwrite($this->SHPFile, packDouble($this->boundingBox['xmax'])); |
253 | 253 | fwrite($this->SHPFile, packDouble($this->boundingBox['ymax'])); |
254 | - fwrite($this->SHPFile, packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0)); |
|
255 | - fwrite($this->SHPFile, packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); |
|
256 | - fwrite($this->SHPFile, packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); |
|
257 | - fwrite($this->SHPFile, packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); |
|
254 | + fwrite($this->SHPFile, packDouble(isset($this->boundingBox['zmin']) ? $this->boundingBox['zmin'] : 0)); |
|
255 | + fwrite($this->SHPFile, packDouble(isset($this->boundingBox['zmax']) ? $this->boundingBox['zmax'] : 0)); |
|
256 | + fwrite($this->SHPFile, packDouble(isset($this->boundingBox['mmin']) ? $this->boundingBox['mmin'] : 0)); |
|
257 | + fwrite($this->SHPFile, packDouble(isset($this->boundingBox['mmax']) ? $this->boundingBox['mmax'] : 0)); |
|
258 | 258 | |
259 | 259 | fwrite($this->SHXFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0)); |
260 | - fwrite($this->SHXFile, pack("N", 50 + 4*count($this->records))); |
|
260 | + fwrite($this->SHXFile, pack("N", 50 + 4 * count($this->records))); |
|
261 | 261 | fwrite($this->SHXFile, pack("V", 1000)); |
262 | 262 | fwrite($this->SHXFile, pack("V", $this->shapeType)); |
263 | 263 | fwrite($this->SHXFile, packDouble($this->boundingBox['xmin'])); |
264 | 264 | fwrite($this->SHXFile, packDouble($this->boundingBox['ymin'])); |
265 | 265 | fwrite($this->SHXFile, packDouble($this->boundingBox['xmax'])); |
266 | 266 | fwrite($this->SHXFile, packDouble($this->boundingBox['ymax'])); |
267 | - fwrite($this->SHXFile, packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0)); |
|
268 | - fwrite($this->SHXFile, packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); |
|
269 | - fwrite($this->SHXFile, packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); |
|
270 | - fwrite($this->SHXFile, packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); |
|
267 | + fwrite($this->SHXFile, packDouble(isset($this->boundingBox['zmin']) ? $this->boundingBox['zmin'] : 0)); |
|
268 | + fwrite($this->SHXFile, packDouble(isset($this->boundingBox['zmax']) ? $this->boundingBox['zmax'] : 0)); |
|
269 | + fwrite($this->SHXFile, packDouble(isset($this->boundingBox['mmin']) ? $this->boundingBox['mmin'] : 0)); |
|
270 | + fwrite($this->SHXFile, packDouble(isset($this->boundingBox['mmax']) ? $this->boundingBox['mmax'] : 0)); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | function _loadRecords() { |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | } |
618 | 618 | } |
619 | 619 | |
620 | - function _loadMultiPointMZRecord( $type ) { |
|
620 | + function _loadMultiPointMZRecord($type) { |
|
621 | 621 | |
622 | 622 | $this->SHPData[$type."min"] = loadData("d", fread($this->SHPFile, 8)); |
623 | 623 | $this->SHPData[$type."max"] = loadData("d", fread($this->SHPFile, 8)); |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | } |
651 | 651 | } |
652 | 652 | |
653 | - function _saveMultiPointMZRecord( $type ) { |
|
653 | + function _saveMultiPointMZRecord($type) { |
|
654 | 654 | |
655 | 655 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
656 | 656 | |
@@ -700,10 +700,10 @@ discard block |
||
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
703 | - fseek($this->SHPFile, $firstIndex + ($readPoints*16)); |
|
703 | + fseek($this->SHPFile, $firstIndex + ($readPoints * 16)); |
|
704 | 704 | } |
705 | 705 | |
706 | - function _loadPolyLineMZRecord( $type ) { |
|
706 | + function _loadPolyLineMZRecord($type) { |
|
707 | 707 | |
708 | 708 | $this->SHPData[$type."min"] = loadData("d", fread($this->SHPFile, 8)); |
709 | 709 | $this->SHPData[$type."max"] = loadData("d", fread($this->SHPFile, 8)); |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | } |
719 | 719 | } |
720 | 720 | |
721 | - fseek($this->SHPFile, $firstIndex + ($readPoints*24)); |
|
721 | + fseek($this->SHPFile, $firstIndex + ($readPoints * 24)); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | function _loadPolyLineMRecord() { |
@@ -740,10 +740,10 @@ discard block |
||
740 | 740 | fwrite($this->SHPFile, pack("VV", $this->SHPData["numparts"], $this->SHPData["numpoints"])); |
741 | 741 | |
742 | 742 | for ($i = 0; $i < $this->SHPData["numparts"]; $i++) { |
743 | - fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])-1)); |
|
743 | + fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i]) - 1)); |
|
744 | 744 | } |
745 | 745 | |
746 | - foreach ($this->SHPData["parts"] as $partData){ |
|
746 | + foreach ($this->SHPData["parts"] as $partData) { |
|
747 | 747 | reset($partData["points"]); |
748 | 748 | while (list($pointIndex, $pointData) = each($partData["points"])) { |
749 | 749 | $this->_savePoint($pointData); |
@@ -751,10 +751,10 @@ discard block |
||
751 | 751 | } |
752 | 752 | } |
753 | 753 | |
754 | - function _savePolyLineMZRecord( $type ) { |
|
754 | + function _savePolyLineMZRecord($type) { |
|
755 | 755 | fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); |
756 | 756 | |
757 | - foreach ($this->SHPData["parts"] as $partData){ |
|
757 | + foreach ($this->SHPData["parts"] as $partData) { |
|
758 | 758 | reset($partData["points"]); |
759 | 759 | while (list($pointIndex, $pointData) = each($partData["points"])) { |
760 | 760 | fwrite($this->SHPFile, packDouble($pointData[$type])); |
@@ -807,8 +807,8 @@ discard block |
||
807 | 807 | case 1: |
808 | 808 | case 11: |
809 | 809 | case 21: |
810 | - if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
811 | - if (in_array($this->shapeType,array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
810 | + if (in_array($this->shapeType, array(11, 21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
811 | + if (in_array($this->shapeType, array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
812 | 812 | //Substitutes the value of the current point |
813 | 813 | $this->SHPData = $point; |
814 | 814 | break; |
@@ -818,8 +818,8 @@ discard block |
||
818 | 818 | case 15: |
819 | 819 | case 23: |
820 | 820 | case 25: |
821 | - if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
822 | - if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
821 | + if (in_array($this->shapeType, array(13, 15, 23, 25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
822 | + if (in_array($this->shapeType, array(13, 15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
823 | 823 | |
824 | 824 | //Adds a new point to the selected part |
825 | 825 | if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
@@ -834,13 +834,13 @@ discard block |
||
834 | 834 | $this->SHPData["parts"][$partIndex]["points"][] = $point; |
835 | 835 | |
836 | 836 | $this->SHPData["numparts"] = count($this->SHPData["parts"]); |
837 | - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
837 | + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"]) ? $this->SHPData["numpoints"] : 0); |
|
838 | 838 | break; |
839 | 839 | case 8: |
840 | 840 | case 18: |
841 | 841 | case 28: |
842 | - if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
843 | - if (in_array($this->shapeType,array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
842 | + if (in_array($this->shapeType, array(18, 28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value |
|
843 | + if (in_array($this->shapeType, array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value |
|
844 | 844 | |
845 | 845 | //Adds a new point |
846 | 846 | if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"]; |
854 | 854 | |
855 | 855 | $this->SHPData["points"][] = $point; |
856 | - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); |
|
856 | + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"]) ? $this->SHPData["numpoints"] : 0); |
|
857 | 857 | break; |
858 | 858 | default: |
859 | 859 | $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); |
@@ -872,8 +872,8 @@ discard block |
||
872 | 872 | //Sets the value of the point to zero |
873 | 873 | $this->SHPData["x"] = 0.0; |
874 | 874 | $this->SHPData["y"] = 0.0; |
875 | - if (in_array($this->shapeType,array(11,21))) $this->SHPData["m"] = 0.0; |
|
876 | - if (in_array($this->shapeType,array(11))) $this->SHPData["z"] = 0.0; |
|
875 | + if (in_array($this->shapeType, array(11, 21))) $this->SHPData["m"] = 0.0; |
|
876 | + if (in_array($this->shapeType, array(11))) $this->SHPData["z"] = 0.0; |
|
877 | 877 | break; |
878 | 878 | case 3: |
879 | 879 | case 5: |
@@ -929,33 +929,33 @@ discard block |
||
929 | 929 | break; |
930 | 930 | case 3: |
931 | 931 | case 5: |
932 | - $result = 22 + 2*count($this->SHPData["parts"]); |
|
932 | + $result = 22 + 2 * count($this->SHPData["parts"]); |
|
933 | 933 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
934 | - $result += 8*count($this->SHPData["parts"][$i]["points"]); |
|
934 | + $result += 8 * count($this->SHPData["parts"][$i]["points"]); |
|
935 | 935 | } |
936 | 936 | break; |
937 | 937 | case 23: |
938 | 938 | case 25: |
939 | - $result = 22 + (2*4) + 2*count($this->SHPData["parts"]); |
|
939 | + $result = 22 + (2 * 4) + 2 * count($this->SHPData["parts"]); |
|
940 | 940 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
941 | - $result += (8+4)*count($this->SHPData["parts"][$i]["points"]); |
|
941 | + $result += (8 + 4) * count($this->SHPData["parts"][$i]["points"]); |
|
942 | 942 | } |
943 | 943 | break; |
944 | 944 | case 13: |
945 | 945 | case 15: |
946 | - $result = 22 + (4*4) + 2*count($this->SHPData["parts"]); |
|
946 | + $result = 22 + (4 * 4) + 2 * count($this->SHPData["parts"]); |
|
947 | 947 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
948 | - $result += (8+8)*count($this->SHPData["parts"][$i]["points"]); |
|
948 | + $result += (8 + 8) * count($this->SHPData["parts"][$i]["points"]); |
|
949 | 949 | } |
950 | 950 | break; |
951 | 951 | case 8: |
952 | - $result = 20 + 8*count($this->SHPData["points"]); |
|
952 | + $result = 20 + 8 * count($this->SHPData["points"]); |
|
953 | 953 | break; |
954 | 954 | case 28: |
955 | - $result = 20 + (2*4) + (8+4)*count($this->SHPData["points"]); |
|
955 | + $result = 20 + (2 * 4) + (8 + 4) * count($this->SHPData["points"]); |
|
956 | 956 | break; |
957 | 957 | case 18: |
958 | - $result = 20 + (4*4) + (8+8)*count($this->SHPData["points"]); |
|
958 | + $result = 20 + (4 * 4) + (8 + 8) * count($this->SHPData["points"]); |
|
959 | 959 | break; |
960 | 960 | default: |
961 | 961 | $result = false; |