Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / phpmyadmin / libraries / plugins / import / ShapeRecord.class.php
blobefefd0c80660a9766501a56b63cf6e2d327af0f0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * This class extends ShapeRecord class to cater the following phpMyAdmin
5 * specific requirements.
7 * @package PhpMyAdmin-Import
8 * @subpackage ESRI_Shape
9 */
10 if (! defined('PHPMYADMIN')) {
11 exit;
14 /**
15 * 1) To load data from .dbf file only when the dBase extension is available.
16 * 2) To use PMA_importGetNextChunk() functionality to read data, rather than
17 * reading directly from a file. Using ImportShp::readFromBuffer() in place
18 * of fread(). This makes it possible to use compressions.
20 * @package PhpMyAdmin-Import
21 * @subpackage ESRI_Shape
23 class PMA_ShapeRecord extends ShapeRecord
25 /**
26 * Loads a geometry data record from the file
28 * @param object &$SHPFile .shp file
29 * @param object &$DBFFile .dbf file
31 * @return void
32 * @see ShapeRecord::loadFromFile()
34 function loadFromFile(&$SHPFile, &$DBFFile)
36 $this->DBFFile = $DBFFile;
37 $this->_loadHeaders();
39 switch ($this->shapeType) {
40 case 0:
41 $this->_loadNullRecord();
42 break;
43 case 1:
44 $this->_loadPointRecord();
45 break;
46 case 3:
47 $this->_loadPolyLineRecord();
48 break;
49 case 5:
50 $this->_loadPolygonRecord();
51 break;
52 case 8:
53 $this->_loadMultiPointRecord();
54 break;
55 default:
56 $this->setError(
57 sprintf(
58 __("Geometry type '%s' is not supported by MySQL."),
59 $this->shapeType
62 break;
64 if (extension_loaded('dbase') && isset($this->DBFFile)) {
65 $this->_loadDBFData();
69 /**
70 * Loads metadata from the ESRI shape record header
72 * @return void
73 * @see ShapeRecord::_loadHeaders()
75 function _loadHeaders()
77 $this->recordNumber = loadData("N", ImportShp::readFromBuffer(4));
78 ImportShp::readFromBuffer(4);
79 $this->shapeType = loadData("V", ImportShp::readFromBuffer(4));
82 /**
83 * Loads data from a point record
85 * @return void
86 * @see ShapeRecord::_loadPoint()
88 function _loadPoint()
90 $data = array();
92 $data["x"] = loadData("d", ImportShp::readFromBuffer(8));
93 $data["y"] = loadData("d", ImportShp::readFromBuffer(8));
95 return $data;
98 /**
99 * Loads data from a multipoint record
101 * @return void
102 * @see ShapeRecord::_loadMultiPointRecord()
104 function _loadMultiPointRecord()
106 $this->SHPData = array();
107 $this->SHPData["xmin"] = loadData("d", ImportShp::readFromBuffer(8));
108 $this->SHPData["ymin"] = loadData("d", ImportShp::readFromBuffer(8));
109 $this->SHPData["xmax"] = loadData("d", ImportShp::readFromBuffer(8));
110 $this->SHPData["ymax"] = loadData("d", ImportShp::readFromBuffer(8));
112 $this->SHPData["numpoints"] = loadData("V", ImportShp::readFromBuffer(4));
114 for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
115 $this->SHPData["points"][] = $this->_loadPoint();
120 * Loads data from a polyline record
122 * @return void
123 * @see ShapeRecord::_loadPolyLineRecord()
125 function _loadPolyLineRecord()
127 $this->SHPData = array();
128 $this->SHPData["xmin"] = loadData("d", ImportShp::readFromBuffer(8));
129 $this->SHPData["ymin"] = loadData("d", ImportShp::readFromBuffer(8));
130 $this->SHPData["xmax"] = loadData("d", ImportShp::readFromBuffer(8));
131 $this->SHPData["ymax"] = loadData("d", ImportShp::readFromBuffer(8));
133 $this->SHPData["numparts"] = loadData("V", ImportShp::readFromBuffer(4));
134 $this->SHPData["numpoints"] = loadData("V", ImportShp::readFromBuffer(4));
136 for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
137 $this->SHPData["parts"][$i] = loadData(
138 "V", ImportShp::readFromBuffer(4)
142 $readPoints = 0;
143 reset($this->SHPData["parts"]);
144 while (list($partIndex, $partData) = each($this->SHPData["parts"])) {
145 if (! isset($this->SHPData["parts"][$partIndex]["points"])
146 || !is_array($this->SHPData["parts"][$partIndex]["points"])
148 $this->SHPData["parts"][$partIndex] = array();
149 $this->SHPData["parts"][$partIndex]["points"] = array();
151 while (! in_array($readPoints, $this->SHPData["parts"])
152 && ($readPoints < ($this->SHPData["numpoints"]))
154 $this->SHPData["parts"][$partIndex]["points"][]
155 = $this->_loadPoint();
156 $readPoints++;