@@ -5,14 +5,14 @@ |
||
5 | 5 | $shp->loadFromFile('data/capitals.*'); |
6 | 6 | |
7 | 7 | $i = 1; |
8 | -foreach($shp->records as $record){ |
|
8 | +foreach ($shp->records as $record) { |
|
9 | 9 | echo "<pre>"; |
10 | 10 | echo "Record No. $i:\n\n\n"; |
11 | 11 | echo "SHP Data = "; |
12 | - print_r($record->SHPData); //All the data related to the point |
|
12 | + print_r($record->SHPData); //All the data related to the point |
|
13 | 13 | print_r("\n\n\n"); |
14 | 14 | echo "DBF Data = "; |
15 | - print_r($record->DBFData); //All the information related to each point |
|
15 | + print_r($record->DBFData); //All the information related to each point |
|
16 | 16 | print_r("\n\n\n"); |
17 | 17 | echo "</pre>"; |
18 | 18 | $i++; |
@@ -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 |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | fwrite($this->SHPFile, pack("dddd", 0, 0, 0, 0)); |
234 | 234 | |
235 | 235 | fwrite($this->SHXFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0)); |
236 | - fwrite($this->SHXFile, pack("N", 50 + 4*count($this->records))); |
|
236 | + fwrite($this->SHXFile, pack("N", 50 + 4 * count($this->records))); |
|
237 | 237 | fwrite($this->SHXFile, pack("V", 1000)); |
238 | 238 | fwrite($this->SHXFile, pack("V", $this->shapeType)); |
239 | 239 | fwrite($this->SHXFile, packDouble($this->boundingBox['xmin'])); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
525 | - fseek($this->SHPFile, $firstIndex + ($readPoints*16)); |
|
525 | + fseek($this->SHPFile, $firstIndex + ($readPoints * 16)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | function _savePolyLineRecord() { |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i]))); |
535 | 535 | } |
536 | 536 | |
537 | - foreach ($this->SHPData["parts"] as $partData){ |
|
537 | + foreach ($this->SHPData["parts"] as $partData) { |
|
538 | 538 | reset($partData["points"]); |
539 | 539 | while (list($pointIndex, $pointData) = each($partData["points"])) { |
540 | 540 | $this->_savePoint($pointData); |
@@ -638,13 +638,13 @@ discard block |
||
638 | 638 | break; |
639 | 639 | case 3: |
640 | 640 | case 5: |
641 | - $result = 22 + 2*count($this->SHPData["parts"]); |
|
641 | + $result = 22 + 2 * count($this->SHPData["parts"]); |
|
642 | 642 | for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { |
643 | - $result += 8*count($this->SHPData["parts"][$i]["points"]); |
|
643 | + $result += 8 * count($this->SHPData["parts"][$i]["points"]); |
|
644 | 644 | } |
645 | 645 | break; |
646 | 646 | case 8: |
647 | - $result = 20 + 8*count($this->SHPData["points"]); |
|
647 | + $result = 20 + 8 * count($this->SHPData["points"]); |
|
648 | 648 | break; |
649 | 649 | default: |
650 | 650 | $result = false; |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | * |
30 | 30 | */ |
31 | 31 | function loadData($type, $data) { |
32 | - if (!$data) return $data; |
|
32 | + if (!$data) { |
|
33 | + return $data; |
|
34 | + } |
|
33 | 35 | $tmp = unpack($type, $data); |
34 | 36 | return current($tmp); |
35 | 37 | } |
@@ -104,7 +106,9 @@ discard block |
||
104 | 106 | } |
105 | 107 | |
106 | 108 | function saveToFile($FileName = NULL) { |
107 | - if ($FileName != NULL) $this->FileName = $FileName; |
|
109 | + if ($FileName != NULL) { |
|
110 | + $this->FileName = $FileName; |
|
111 | + } |
|
108 | 112 | |
109 | 113 | if (($this->_openSHPFile(TRUE)) && ($this->_openSHXFile(TRUE)) && ($this->_openDBFFile(TRUE))) { |
110 | 114 | $this->_saveHeaders(); |
@@ -562,10 +566,18 @@ discard block |
||
562 | 566 | case 3: |
563 | 567 | case 5: |
564 | 568 | //Adds a new point to the selected part |
565 | - if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
566 | - if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
567 | - if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
568 | - if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
569 | + if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) { |
|
570 | + $this->SHPData["xmin"] = $point["x"]; |
|
571 | + } |
|
572 | + if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) { |
|
573 | + $this->SHPData["ymin"] = $point["y"]; |
|
574 | + } |
|
575 | + if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) { |
|
576 | + $this->SHPData["xmax"] = $point["x"]; |
|
577 | + } |
|
578 | + if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) { |
|
579 | + $this->SHPData["ymax"] = $point["y"]; |
|
580 | + } |
|
569 | 581 | |
570 | 582 | $this->SHPData["parts"][$partIndex]["points"][] = $point; |
571 | 583 | |
@@ -574,10 +586,18 @@ discard block |
||
574 | 586 | break; |
575 | 587 | case 8: |
576 | 588 | //Adds a new point |
577 | - if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"]; |
|
578 | - if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"]; |
|
579 | - if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"]; |
|
580 | - if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"]; |
|
589 | + if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) { |
|
590 | + $this->SHPData["xmin"] = $point["x"]; |
|
591 | + } |
|
592 | + if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) { |
|
593 | + $this->SHPData["ymin"] = $point["y"]; |
|
594 | + } |
|
595 | + if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) { |
|
596 | + $this->SHPData["xmax"] = $point["x"]; |
|
597 | + } |
|
598 | + if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) { |
|
599 | + $this->SHPData["ymax"] = $point["y"]; |
|
600 | + } |
|
581 | 601 | |
582 | 602 | $this->SHPData["points"][] = $point; |
583 | 603 | $this->SHPData["numpoints"]++; |
@@ -5,14 +5,14 @@ |
||
5 | 5 | $shp->loadFromFile('data/mexico.*'); |
6 | 6 | |
7 | 7 | $i = 1; |
8 | -foreach($shp->records as $record){ |
|
8 | +foreach ($shp->records as $record) { |
|
9 | 9 | echo "<pre>"; |
10 | 10 | echo "Record No. $i:\n\n\n"; |
11 | 11 | echo "SHP Data = "; |
12 | - print_r($record->SHPData); //All the data related to the poligon |
|
12 | + print_r($record->SHPData); //All the data related to the poligon |
|
13 | 13 | print_r("\n\n\n"); |
14 | 14 | echo "DBF Data = "; |
15 | - print_r($record->DBFData); //All the information related to each poligon |
|
15 | + print_r($record->DBFData); //All the information related to each poligon |
|
16 | 16 | print_r("\n\n\n"); |
17 | 17 | echo "</pre>"; |
18 | 18 | $i++; |