2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * This class extends ShapeRecord class to cater the following phpMyAdmin
5 * specific requirements.
7 * @package PhpMyAdmin-Import
8 * @subpackage ESRI_Shape
10 if (! defined('PHPMYADMIN')) {
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
26 * Loads a geometry data record from the file
28 * @param object &$SHPFile .shp file
29 * @param object &$DBFFile .dbf file
32 * @see ShapeRecord::loadFromFile()
34 function loadFromFile(&$SHPFile, &$DBFFile)
36 $this->DBFFile
= $DBFFile;
37 $this->_loadHeaders();
39 switch ($this->shapeType
) {
41 $this->_loadNullRecord();
44 $this->_loadPointRecord();
47 $this->_loadPolyLineRecord();
50 $this->_loadPolygonRecord();
53 $this->_loadMultiPointRecord();
58 __("Geometry type '%s' is not supported by MySQL."),
64 if (extension_loaded('dbase') && isset($this->DBFFile
)) {
65 $this->_loadDBFData();
70 * Loads metadata from the ESRI shape record header
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));
83 * Loads data from a point record
86 * @see ShapeRecord::_loadPoint()
92 $data["x"] = loadData("d", ImportShp
::readFromBuffer(8));
93 $data["y"] = loadData("d", ImportShp
::readFromBuffer(8));
99 * Loads data from a multipoint record
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
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)
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();