ShapeFile.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * This class extends ShapeFile class to cater the following phpMyAdmin
  5. * specific requirements.
  6. *
  7. * @package PhpMyAdmin-Import
  8. * @subpackage ESRI_Shape
  9. */
  10. if (! defined('PHPMYADMIN')) {
  11. exit;
  12. }
  13. /**
  14. * 1) To load data from .dbf file only when the dBase extension is available.
  15. * 2) To use PMA_importGetNextChunk() functionality to read data, rather than
  16. * reading directly from a file. Using ImportShp::readFromBuffer() in place
  17. * of fread(). This makes it possible to use compressions.
  18. *
  19. * @package PhpMyAdmin-Import
  20. * @subpackage ESRI_Shape
  21. */
  22. class PMA_ShapeFile extends ShapeFile
  23. {
  24. /**
  25. * Returns whether the 'dbase' extension is loaded
  26. *
  27. * @return boolean whether the 'dbase' extension is loaded
  28. */
  29. function _isDbaseLoaded()
  30. {
  31. return extension_loaded('dbase');
  32. }
  33. /**
  34. * Loads ESRI shape data from the imported file
  35. *
  36. * @param string $FileName not used, it's here only to match the method
  37. * signature of the method being overidden
  38. *
  39. * @return void
  40. * @see ShapeFile::loadFromFile()
  41. */
  42. function loadFromFile($FileName)
  43. {
  44. $this->_loadHeaders();
  45. $this->_loadRecords();
  46. if ($this->_isDbaseLoaded()) {
  47. $this->_closeDBFFile();
  48. }
  49. }
  50. /**
  51. * Loads metadata from the ESRI shape file header
  52. *
  53. * @return void
  54. * @see ShapeFile::_loadHeaders()
  55. */
  56. function _loadHeaders()
  57. {
  58. ImportShp::readFromBuffer(24);
  59. $this->fileLength = loadData("N", ImportShp::readFromBuffer(4));
  60. ImportShp::readFromBuffer(4);
  61. $this->shapeType = loadData("V", ImportShp::readFromBuffer(4));
  62. $this->boundingBox = array();
  63. $this->boundingBox["xmin"] = loadData("d", ImportShp::readFromBuffer(8));
  64. $this->boundingBox["ymin"] = loadData("d", ImportShp::readFromBuffer(8));
  65. $this->boundingBox["xmax"] = loadData("d", ImportShp::readFromBuffer(8));
  66. $this->boundingBox["ymax"] = loadData("d", ImportShp::readFromBuffer(8));
  67. if ($this->_isDbaseLoaded() && $this->_openDBFFile()) {
  68. $this->DBFHeader = $this->_loadDBFHeader();
  69. }
  70. }
  71. /**
  72. * Loads geometry data from the ESRI shape file
  73. *
  74. * @return void
  75. * @see ShapeFile::_loadRecords()
  76. */
  77. function _loadRecords()
  78. {
  79. global $eof;
  80. ImportShp::readFromBuffer(32);
  81. while (true) {
  82. $record = new PMA_ShapeRecord(-1);
  83. $record->loadFromFile($this->SHPFile, $this->DBFFile);
  84. if ($record->lastError != "") {
  85. return false;
  86. }
  87. if ($eof) {
  88. break;
  89. }
  90. $this->records[] = $record;
  91. }
  92. }
  93. }
  94. ?>