Update website
This commit is contained in:
parent
4413528994
commit
1d90fbf296
6865 changed files with 1091082 additions and 0 deletions
131
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/CHANGELOG.md
vendored
Normal file
131
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/CHANGELOG.md
vendored
Normal file
|
@ -0,0 +1,131 @@
|
|||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [3.0.1] - 2021-02-05
|
||||
### Fixed
|
||||
- Fix method signature of ShapeFile::getDBFHeader()
|
||||
|
||||
## [3.0.0] - 2021-02-05
|
||||
### Added
|
||||
- Support for PHPUnit 8 and 9
|
||||
- Support PHP 8
|
||||
|
||||
### Changed
|
||||
- Enable strict mode on PHP files
|
||||
- Rename ShapeFile::$FileName property to ShapeFile::$fileName
|
||||
- Rename ShapeRecord::$SHPData property to ShapeRecord::$shpData
|
||||
- Rename ShapeRecord::$DBFData property to ShapeRecord::$dbfData
|
||||
- ShapeRecord::getContentLength returns `null` when the shape type is not supported instead of `false`.
|
||||
|
||||
### Removed
|
||||
- Drop support for PHP 5.4, PHP 5.5, PHP 5.6, PHP 7.0 and HHVM
|
||||
|
||||
## [2.1] - 2017-05-15
|
||||
### Changed
|
||||
- Documentation improvements.
|
||||
|
||||
## [2.0] - 2017-01-23
|
||||
### Changed
|
||||
- Switched to PhpMyAdmin vendor namespace to follow PSR-4.
|
||||
|
||||
## [1.2] - 2017-01-07
|
||||
### Added
|
||||
- PHP 7.2 support.
|
||||
|
||||
### Changed
|
||||
- Coding style cleanup.
|
||||
- Avoid installing tests and test data using composer.
|
||||
|
||||
## [1.1] - 2016-11-21
|
||||
### Fixed
|
||||
- Fixed adjusting of record bounding box
|
||||
|
||||
## [1.0] - 2016-11-21
|
||||
### Changed
|
||||
- Documentation improvements
|
||||
- Code cleanups
|
||||
|
||||
## [0.13] - 2016-11-21
|
||||
### Changed
|
||||
- Code cleanups
|
||||
- Improved test coverage
|
||||
|
||||
## [0.12] - 2016-11-17
|
||||
### Changed
|
||||
- Improved test coverage
|
||||
|
||||
### Fixed
|
||||
- Fixed DBF search
|
||||
|
||||
## [0.11] - 2016-11-16
|
||||
### Changed
|
||||
- Code cleanups
|
||||
|
||||
### Fixed
|
||||
- Fixed behavior without configured DBF header
|
||||
- Fixed saving Polygon/Polyline creation with multiple parts
|
||||
- Fixed saving Multipont records
|
||||
|
||||
## [0.10] - 2016-09-05
|
||||
### Changed
|
||||
- Improved error handling on loading
|
||||
|
||||
## [0.9] - 2016-08-04
|
||||
### Changed
|
||||
- Code cleanups
|
||||
|
||||
## [0.8] - 2016-06-24
|
||||
### Changed
|
||||
- Code cleanups
|
||||
|
||||
### Fixed
|
||||
- Fixed loading of records with optional data
|
||||
|
||||
## [0.7] - 2016-06-24
|
||||
### Fixed
|
||||
- Properly fail on loading corrupted files
|
||||
|
||||
## [0.6] - 2016-06-24
|
||||
### Fixed
|
||||
- Fixed detection of end of file when loading
|
||||
|
||||
## [0.5] - 2016-06-24
|
||||
### Added
|
||||
- Added getShapeName method to ShapeFile
|
||||
|
||||
## [0.4] - 2016-06-24
|
||||
### Changed
|
||||
- Make API work even without real file open
|
||||
|
||||
## [0.3] - 2016-06-24
|
||||
### Added
|
||||
- Better support for subclassing
|
||||
|
||||
## [0.2] - 2016-06-24
|
||||
### Changed
|
||||
- Make the dbase extension optional dependency
|
||||
|
||||
## 0.1 - 2016-06-14
|
||||
### Added
|
||||
- Inital release based on bfShapeFiles
|
||||
|
||||
[Unreleased]: https://github.com/phpmyadmin/shapefile/compare/2.1...HEAD
|
||||
[2.1]: https://github.com/phpmyadmin/shapefile/compare/2.0...2.1
|
||||
[2.0]: https://github.com/phpmyadmin/shapefile/compare/1.2...2.0
|
||||
[1.2]: https://github.com/phpmyadmin/shapefile/compare/1.1...1.2
|
||||
[1.1]: https://github.com/phpmyadmin/shapefile/compare/1.0...1.1
|
||||
[1.0]: https://github.com/phpmyadmin/shapefile/compare/0.13...1.0
|
||||
[0.13]: https://github.com/phpmyadmin/shapefile/compare/0.12...0.13
|
||||
[0.12]: https://github.com/phpmyadmin/shapefile/compare/0.11...0.12
|
||||
[0.11]: https://github.com/phpmyadmin/shapefile/compare/0.10...0.11
|
||||
[0.10]: https://github.com/phpmyadmin/shapefile/compare/0.9...0.10
|
||||
[0.9]: https://github.com/phpmyadmin/shapefile/compare/0.8...0.9
|
||||
[0.8]: https://github.com/phpmyadmin/shapefile/compare/0.7...0.8
|
||||
[0.7]: https://github.com/phpmyadmin/shapefile/compare/0.6...0.7
|
||||
[0.6]: https://github.com/phpmyadmin/shapefile/compare/0.5...0.6
|
||||
[0.5]: https://github.com/phpmyadmin/shapefile/compare/0.4...0.5
|
||||
[0.4]: https://github.com/phpmyadmin/shapefile/compare/0.3...0.4
|
||||
[0.3]: https://github.com/phpmyadmin/shapefile/compare/0.2...0.3
|
||||
[0.2]: https://github.com/phpmyadmin/shapefile/compare/0.1...0.2
|
339
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/LICENSE
vendored
Normal file
339
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/LICENSE
vendored
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
57
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/README.md
vendored
Normal file
57
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/README.md
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
# shapefile
|
||||
ShapeFile library for PHP
|
||||
|
||||

|
||||
[](https://codecov.io/github/phpmyadmin/shapefile?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/phpmyadmin/shapefile/?branch=master)
|
||||
[](https://packagist.org/packages/phpmyadmin/shapefile)
|
||||
|
||||
## Features
|
||||
|
||||
Currently the 2D and 3D variants except MultiPatch of the ShapeFile format as
|
||||
defined in https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf. The
|
||||
library currently supports reading and editing of ShapeFiles and the Associated
|
||||
information (DBF file). There are a lot of things that can be improved in the
|
||||
code, if you are interested in developing, helping with the documentation,
|
||||
making translations or offering new ideas please contact us.
|
||||
|
||||
## Installation
|
||||
|
||||
Please use [Composer][1] to install:
|
||||
|
||||
```sh
|
||||
composer require phpmyadmin/shapefile
|
||||
```
|
||||
|
||||
To be able to read and write the associated DBF file, you need ``dbase``
|
||||
extension:
|
||||
|
||||
```sh
|
||||
pecl install dbase
|
||||
echo "extension=dbase.so" > /etc/php7/conf.d/dbase.ini
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
The API documentation is available at
|
||||
<https://develdocs.phpmyadmin.net/shapefile/>.
|
||||
|
||||
## Usage
|
||||
|
||||
To read shape file:
|
||||
|
||||
```php
|
||||
$shp = new \PhpMyAdmin\ShapeFile\ShapeFile(0);
|
||||
$shp->loadFromFile('path/file.*');
|
||||
```
|
||||
|
||||
## History
|
||||
|
||||
This library is based on BytesFall ShapeFiles library written by Ovidio (ovidio
|
||||
AT users.sourceforge.net). The library has been embedded in phpMyAdmin for
|
||||
years and slowly developed there. At one point people started to use our
|
||||
version rather than the original library and that was the point we decided to
|
||||
make it separate package.
|
||||
|
||||
[1]:https://getcomposer.org/
|
||||
|
49
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/composer.json
vendored
Normal file
49
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/composer.json
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "phpmyadmin/shapefile",
|
||||
"description": "ESRI ShapeFile library for PHP",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"keywords": ["shapefile", "shp", "geo", "geospatial", "dbf", "ESRI", "shape"],
|
||||
"homepage": "https://github.com/phpmyadmin/shapefile",
|
||||
"authors": [
|
||||
{
|
||||
"name": "The phpMyAdmin Team",
|
||||
"email": "developers@phpmyadmin.net",
|
||||
"homepage": "https://www.phpmyadmin.net/team/"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpmyadmin/shapefile/issues",
|
||||
"source": "https://github.com/phpmyadmin/shapefile"
|
||||
},
|
||||
"scripts": {
|
||||
"phpcbf": "phpcbf",
|
||||
"phpcs": "phpcs",
|
||||
"phpstan": "phpstan analyse",
|
||||
"phpunit": "phpunit --color=always",
|
||||
"test": [
|
||||
"@phpcs",
|
||||
"@phpstan",
|
||||
"@phpunit"
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-dbase": "For dbf files parsing"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^0.12.37",
|
||||
"phpmyadmin/coding-standard": "^2.1.1",
|
||||
"phpstan/phpstan-phpunit": "^0.12.6",
|
||||
"phpunit/phpunit": "^7.4 || ^8 || ^9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpMyAdmin\\ShapeFile\\": "src"
|
||||
}
|
||||
},
|
||||
"config":{
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
696
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/src/ShapeFile.php
vendored
Normal file
696
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/src/ShapeFile.php
vendored
Normal file
|
@ -0,0 +1,696 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpMyAdmin ShapeFile library
|
||||
* <https://github.com/phpmyadmin/shapefile/>.
|
||||
*
|
||||
* Copyright 2006-2007 Ovidio <ovidio AT users.sourceforge.net>
|
||||
* Copyright 2016 - 2017 Michal Čihař <michal@cihar.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can download one from
|
||||
* https://www.gnu.org/copyleft/gpl.html.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\ShapeFile;
|
||||
|
||||
use function array_push;
|
||||
use function chr;
|
||||
use function count;
|
||||
use function extension_loaded;
|
||||
use function fclose;
|
||||
use function feof;
|
||||
use function file_exists;
|
||||
use function fopen;
|
||||
use function fread;
|
||||
use function fwrite;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_readable;
|
||||
use function ord;
|
||||
use function pack;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
use function strtoupper;
|
||||
use function substr;
|
||||
use function trim;
|
||||
use function unlink;
|
||||
|
||||
/**
|
||||
* ShapeFile class.
|
||||
*/
|
||||
class ShapeFile
|
||||
{
|
||||
public const MAGIC = 0x270a;
|
||||
|
||||
/** @var string|null */
|
||||
public $fileName;
|
||||
|
||||
/** @var resource|null */
|
||||
private $shpFile = null;
|
||||
/** @var resource|null */
|
||||
private $shxFile = null;
|
||||
/** @var resource|null */
|
||||
private $dbfFile = null;
|
||||
|
||||
/** @var array|null */
|
||||
private $dbfHeader;
|
||||
|
||||
/** @var string */
|
||||
public $lastError = '';
|
||||
|
||||
/** @var array */
|
||||
public $boundingBox = [
|
||||
'xmin' => 0.0,
|
||||
'ymin' => 0.0,
|
||||
'xmax' => 0.0,
|
||||
'ymax' => 0.0,
|
||||
];
|
||||
/** @var int */
|
||||
private $fileLength = 0;
|
||||
|
||||
/** @var int|false */
|
||||
public $shapeType = 0;
|
||||
|
||||
/** @var array */
|
||||
public $records = [];
|
||||
|
||||
/**
|
||||
* Checks whether dbase manipulations are supported.
|
||||
*/
|
||||
public static function supportsDbase(): bool
|
||||
{
|
||||
return extension_loaded('dbase');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $shapeType File shape type, should be same as all records
|
||||
* @param array $boundingBox File bounding box
|
||||
* @param string|null $fileName File name
|
||||
*/
|
||||
public function __construct(
|
||||
int $shapeType,
|
||||
array $boundingBox = [
|
||||
'xmin' => 0.0,
|
||||
'ymin' => 0.0,
|
||||
'xmax' => 0.0,
|
||||
'ymax' => 0.0,
|
||||
],
|
||||
?string $fileName = null
|
||||
) {
|
||||
$this->shapeType = $shapeType;
|
||||
$this->boundingBox = $boundingBox;
|
||||
$this->fileName = $fileName;
|
||||
|
||||
/**
|
||||
* The value for file length is the total length of the file in 16-bit words
|
||||
* (including the fifty 16-bit words that make up the header).
|
||||
*/
|
||||
$this->fileLength = 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads shapefile and dbase (if supported).
|
||||
*
|
||||
* @param string $fileName File mask to load (eg. example.*)
|
||||
*/
|
||||
public function loadFromFile(string $fileName): bool
|
||||
{
|
||||
if (! empty($fileName)) {
|
||||
$this->fileName = $fileName;
|
||||
$result = $this->openSHPFile();
|
||||
} else {
|
||||
/* We operate on buffer emulated by readSHP / eofSHP */
|
||||
$result = true;
|
||||
}
|
||||
|
||||
if ($result && ($this->openDBFFile())) {
|
||||
if (! $this->loadHeaders()) {
|
||||
$this->closeSHPFile();
|
||||
$this->closeDBFFile();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->loadRecords()) {
|
||||
$this->closeSHPFile();
|
||||
$this->closeDBFFile();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->closeSHPFile();
|
||||
$this->closeDBFFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves shapefile.
|
||||
*
|
||||
* @param string|null $fileName Name of file, otherwise existing is used
|
||||
*/
|
||||
public function saveToFile(?string $fileName = null): bool
|
||||
{
|
||||
if ($fileName !== null) {
|
||||
$this->fileName = $fileName;
|
||||
}
|
||||
|
||||
if (! $this->openSHPFile(true) || (! $this->openSHXFile(true)) || (! $this->createDBFFile())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->saveHeaders();
|
||||
$this->saveRecords();
|
||||
$this->closeSHPFile();
|
||||
$this->closeSHXFile();
|
||||
$this->closeDBFFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates filename with given extension.
|
||||
*
|
||||
* @param string $extension Extension to use (including dot)
|
||||
*/
|
||||
private function getFilename(string $extension): string
|
||||
{
|
||||
return str_replace('.*', $extension, (string) $this->fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates bounding box based on shpData.
|
||||
*
|
||||
* @param string $type Type of box
|
||||
* @param array $data ShapeRecord shpData
|
||||
*/
|
||||
private function updateBBox(string $type, array $data): void
|
||||
{
|
||||
$min = $type . 'min';
|
||||
$max = $type . 'max';
|
||||
|
||||
if (! isset($this->boundingBox[$min])
|
||||
|| $this->boundingBox[$min] == 0.0
|
||||
|| ($this->boundingBox[$min] > $data[$min])
|
||||
) {
|
||||
$this->boundingBox[$min] = $data[$min];
|
||||
}
|
||||
|
||||
if (isset($this->boundingBox[$max])
|
||||
&& $this->boundingBox[$max] != 0.0
|
||||
&& ($this->boundingBox[$max] >= $data[$max])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->boundingBox[$max] = $data[$max];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds record to shape file.
|
||||
*
|
||||
* @return int Number of added record
|
||||
*/
|
||||
public function addRecord(ShapeRecord $record): int
|
||||
{
|
||||
if (isset($this->dbfHeader) && (is_array($this->dbfHeader))) {
|
||||
$record->updateDBFInfo($this->dbfHeader);
|
||||
}
|
||||
|
||||
$this->fileLength += $record->getContentLength() + 4;
|
||||
$this->records[] = $record;
|
||||
$this->records[count($this->records) - 1]->recordNumber = count($this->records);
|
||||
|
||||
$this->updateBBox('x', $record->shpData);
|
||||
$this->updateBBox('y', $record->shpData);
|
||||
|
||||
if (in_array($this->shapeType, [11, 13, 15, 18, 21, 23, 25, 28])) {
|
||||
$this->updateBBox('m', $record->shpData);
|
||||
}
|
||||
|
||||
if (in_array($this->shapeType, [11, 13, 15, 18])) {
|
||||
$this->updateBBox('z', $record->shpData);
|
||||
}
|
||||
|
||||
return count($this->records) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes record from shapefile.
|
||||
*/
|
||||
public function deleteRecord(int $index): void
|
||||
{
|
||||
if (! isset($this->records[$index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fileLength -= $this->records[$index]->getContentLength() + 4;
|
||||
$count = count($this->records) - 1;
|
||||
for ($i = $index; $i < $count; ++$i) {
|
||||
$this->records[$i] = $this->records[$i + 1];
|
||||
}
|
||||
|
||||
unset($this->records[count($this->records) - 1]);
|
||||
$this->deleteRecordFromDBF($index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array defining fields in DBF file.
|
||||
*
|
||||
* @return array|null see setDBFHeader for more information
|
||||
*/
|
||||
public function getDBFHeader(): ?array
|
||||
{
|
||||
return $this->dbfHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes array defining fields in DBF file, used in dbase_create call.
|
||||
*
|
||||
* @param array $header An array of arrays, each array describing the
|
||||
* format of one field of the database. Each
|
||||
* field consists of a name, a character indicating
|
||||
* the field type, and optionally, a length,
|
||||
* a precision and a nullable flag.
|
||||
*/
|
||||
public function setDBFHeader(array $header): void
|
||||
{
|
||||
$this->dbfHeader = $header;
|
||||
|
||||
$count = count($this->records);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$this->records[$i]->updateDBFInfo($header);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookups value in the DBF file and returns index.
|
||||
*
|
||||
* @param string $field Field to match
|
||||
* @param mixed $value Value to match
|
||||
*/
|
||||
public function getIndexFromDBFData(string $field, $value): int
|
||||
{
|
||||
foreach ($this->records as $index => $record) {
|
||||
if (isset($record->dbfData[$field]) &&
|
||||
(trim(strtoupper($record->dbfData[$field])) === strtoupper($value))
|
||||
) {
|
||||
return $index;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads DBF metadata.
|
||||
*/
|
||||
private function loadDBFHeader(): array
|
||||
{
|
||||
$DBFFile = fopen($this->getFilename('.dbf'), 'r');
|
||||
|
||||
$result = [];
|
||||
$i = 1;
|
||||
$inHeader = true;
|
||||
|
||||
while ($inHeader) {
|
||||
if (! feof($DBFFile)) {
|
||||
$buff32 = fread($DBFFile, 32);
|
||||
if ($i > 1) {
|
||||
if (substr($buff32, 0, 1) === chr(13)) {
|
||||
$inHeader = false;
|
||||
} else {
|
||||
$pos = strpos(substr($buff32, 0, 10), chr(0));
|
||||
$pos = ($pos === false ? 10 : $pos);
|
||||
|
||||
$fieldName = substr($buff32, 0, $pos);
|
||||
$fieldType = substr($buff32, 11, 1);
|
||||
$fieldLen = ord(substr($buff32, 16, 1));
|
||||
$fieldDec = ord(substr($buff32, 17, 1));
|
||||
|
||||
array_push($result, [$fieldName, $fieldType, $fieldLen, $fieldDec]);
|
||||
}
|
||||
}
|
||||
|
||||
++$i;
|
||||
} else {
|
||||
$inHeader = false;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($DBFFile);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes record from the DBF file.
|
||||
*/
|
||||
private function deleteRecordFromDBF(int $index): void
|
||||
{
|
||||
if ($this->dbfFile === null || ! @dbase_delete_record($this->dbfFile, $index)) {
|
||||
return;
|
||||
}
|
||||
|
||||
dbase_pack($this->dbfFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads SHP file metadata.
|
||||
*/
|
||||
private function loadHeaders(): bool
|
||||
{
|
||||
if (Util::loadData('N', $this->readSHP(4)) !== self::MAGIC) {
|
||||
$this->setError('Not a SHP file (file code mismatch)');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Skip 20 unused bytes */
|
||||
$this->readSHP(20);
|
||||
|
||||
$this->fileLength = Util::loadData('N', $this->readSHP(4));
|
||||
|
||||
/* We currently ignore version */
|
||||
$this->readSHP(4);
|
||||
|
||||
$this->shapeType = Util::loadData('V', $this->readSHP(4));
|
||||
|
||||
$this->boundingBox = [];
|
||||
$this->boundingBox['xmin'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['ymin'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['xmax'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['ymax'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['zmin'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['zmax'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['mmin'] = Util::loadData('d', $this->readSHP(8));
|
||||
$this->boundingBox['mmax'] = Util::loadData('d', $this->readSHP(8));
|
||||
|
||||
if (self::supportsDbase()) {
|
||||
$this->dbfHeader = $this->loadDBFHeader();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves bounding box record, possibly using 0 instead of not set values.
|
||||
*
|
||||
* @param resource $file File object
|
||||
* @param string $type Bounding box dimension (eg. xmax, mmin...)
|
||||
*/
|
||||
private function saveBBoxRecord($file, string $type): void
|
||||
{
|
||||
fwrite($file, Util::packDouble(
|
||||
$this->boundingBox[$type] ?? 0
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves bounding box to a file.
|
||||
*
|
||||
* @param resource $file File object
|
||||
*/
|
||||
private function saveBBox($file): void
|
||||
{
|
||||
$this->saveBBoxRecord($file, 'xmin');
|
||||
$this->saveBBoxRecord($file, 'ymin');
|
||||
$this->saveBBoxRecord($file, 'xmax');
|
||||
$this->saveBBoxRecord($file, 'ymax');
|
||||
$this->saveBBoxRecord($file, 'zmin');
|
||||
$this->saveBBoxRecord($file, 'zmax');
|
||||
$this->saveBBoxRecord($file, 'mmin');
|
||||
$this->saveBBoxRecord($file, 'mmax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves SHP and SHX file metadata.
|
||||
*/
|
||||
private function saveHeaders(): void
|
||||
{
|
||||
fwrite($this->shpFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0));
|
||||
fwrite($this->shpFile, pack('N', $this->fileLength));
|
||||
fwrite($this->shpFile, pack('V', 1000));
|
||||
fwrite($this->shpFile, pack('V', $this->shapeType));
|
||||
$this->saveBBox($this->shpFile);
|
||||
|
||||
fwrite($this->shxFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0));
|
||||
fwrite($this->shxFile, pack('N', 50 + 4 * count($this->records)));
|
||||
fwrite($this->shxFile, pack('V', 1000));
|
||||
fwrite($this->shxFile, pack('V', $this->shapeType));
|
||||
$this->saveBBox($this->shxFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads records from SHP file (and DBF).
|
||||
*/
|
||||
private function loadRecords(): bool
|
||||
{
|
||||
/* Need to start at offset 100 */
|
||||
while (! $this->eofSHP()) {
|
||||
$record = new ShapeRecord(-1);
|
||||
$record->loadFromFile($this, $this->shpFile, $this->dbfFile);
|
||||
if ($record->lastError !== '') {
|
||||
$this->setError($record->lastError);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($record->shapeType === false || $record->shapeType === '') && $this->eofSHP()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->records[] = $record;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves records to SHP and SHX files.
|
||||
*/
|
||||
private function saveRecords(): void
|
||||
{
|
||||
$offset = 50;
|
||||
if (! is_array($this->records) || (count($this->records) <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->records as $index => $record) {
|
||||
//Save the record to the .shp file
|
||||
$record->saveToFile($this->shpFile, $this->dbfFile, $index + 1);
|
||||
|
||||
//Save the record to the .shx file
|
||||
fwrite($this->shxFile, pack('N', $offset));
|
||||
fwrite($this->shxFile, pack('N', $record->getContentLength()));
|
||||
$offset += 4 + $record->getContentLength();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic interface to open files.
|
||||
*
|
||||
* @param bool $toWrite Whether file should be opened for writing
|
||||
* @param string $extension File extension
|
||||
* @param string $name Verbose file name to report errors
|
||||
*
|
||||
* @return resource|false File handle
|
||||
*/
|
||||
private function openFile(bool $toWrite, string $extension, string $name)
|
||||
{
|
||||
$shpName = $this->getFilename($extension);
|
||||
$result = @fopen($shpName, ($toWrite ? 'wb+' : 'rb'));
|
||||
if (! $result) {
|
||||
$this->setError(sprintf('It wasn\'t possible to open the %s file "%s"', $name, $shpName));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens SHP file.
|
||||
*
|
||||
* @param bool $toWrite Whether file should be opened for writing
|
||||
*/
|
||||
private function openSHPFile(bool $toWrite = false): bool
|
||||
{
|
||||
$this->shpFile = $this->openFile($toWrite, '.shp', 'Shape');
|
||||
|
||||
return (bool) $this->shpFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes SHP file.
|
||||
*/
|
||||
private function closeSHPFile(): void
|
||||
{
|
||||
if (! $this->shpFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
fclose($this->shpFile);
|
||||
$this->shpFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens SHX file.
|
||||
*
|
||||
* @param bool $toWrite Whether file should be opened for writing
|
||||
*/
|
||||
private function openSHXFile(bool $toWrite = false): bool
|
||||
{
|
||||
$this->shxFile = $this->openFile($toWrite, '.shx', 'Index');
|
||||
|
||||
return (bool) $this->shxFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes SHX file.
|
||||
*/
|
||||
private function closeSHXFile(): void
|
||||
{
|
||||
if (! $this->shxFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
fclose($this->shxFile);
|
||||
$this->shxFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates DBF file.
|
||||
*/
|
||||
private function createDBFFile(): bool
|
||||
{
|
||||
if (! self::supportsDbase() || ! is_array($this->dbfHeader) || count($this->dbfHeader) === 0) {
|
||||
$this->dbfFile = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$dbfName = $this->getFilename('.dbf');
|
||||
|
||||
/* Unlink existing file */
|
||||
if (file_exists($dbfName)) {
|
||||
unlink($dbfName);
|
||||
}
|
||||
|
||||
/* Create new file */
|
||||
$this->dbfFile = @dbase_create($dbfName, $this->dbfHeader);
|
||||
if ($this->dbfFile === false) {
|
||||
$this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbfName));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads DBF file if supported.
|
||||
*/
|
||||
private function openDBFFile(): bool
|
||||
{
|
||||
if (! self::supportsDbase()) {
|
||||
$this->dbfFile = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$dbfName = $this->getFilename('.dbf');
|
||||
if (! is_readable($dbfName)) {
|
||||
$this->setError(sprintf('It wasn\'t possible to find the DBase file "%s"', $dbfName));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->dbfFile = @dbase_open($dbfName, 0);
|
||||
if (! $this->dbfFile) {
|
||||
$this->setError(sprintf('It wasn\'t possible to open the DBase file "%s"', $dbfName));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes DBF file.
|
||||
*/
|
||||
private function closeDBFFile(): void
|
||||
{
|
||||
if (! $this->dbfFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
dbase_close($this->dbfFile);
|
||||
$this->dbfFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets error message.
|
||||
*/
|
||||
public function setError(string $error): void
|
||||
{
|
||||
$this->lastError = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads given number of bytes from SHP file.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function readSHP(int $bytes)
|
||||
{
|
||||
if ($this->shpFile === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fread($this->shpFile, $bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether file is at EOF.
|
||||
*/
|
||||
public function eofSHP(): bool
|
||||
{
|
||||
return feof($this->shpFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shape name.
|
||||
*/
|
||||
public function getShapeName(): string
|
||||
{
|
||||
return Util::nameShape($this->shapeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether file contains measure data.
|
||||
*
|
||||
* For some reason this is distinguished by zero bounding box in the
|
||||
* specification.
|
||||
*/
|
||||
public function hasMeasure(): bool
|
||||
{
|
||||
return $this->boundingBox['mmin'] != 0 || $this->boundingBox['mmax'] != 0;
|
||||
}
|
||||
}
|
900
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/src/ShapeRecord.php
vendored
Normal file
900
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/src/ShapeRecord.php
vendored
Normal file
|
@ -0,0 +1,900 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpMyAdmin ShapeFile library
|
||||
* <https://github.com/phpmyadmin/shapefile/>.
|
||||
*
|
||||
* Copyright 2006-2007 Ovidio <ovidio AT users.sourceforge.net>
|
||||
* Copyright 2016 - 2017 Michal Čihař <michal@cihar.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can download one from
|
||||
* https://www.gnu.org/copyleft/gpl.html.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\ShapeFile;
|
||||
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function fwrite;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function pack;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* ShapeFile record class.
|
||||
*/
|
||||
class ShapeRecord
|
||||
{
|
||||
/** @var resource */
|
||||
private $shpFile = null;
|
||||
/** @var resource */
|
||||
private $dbfFile = null;
|
||||
/** @var ShapeFile */
|
||||
private $shapeFile = null;
|
||||
|
||||
/** @var int */
|
||||
private $size = 0;
|
||||
/** @var int */
|
||||
private $read = 0;
|
||||
|
||||
/** @var int|null */
|
||||
public $recordNumber = null;
|
||||
|
||||
/** @var int */
|
||||
public $shapeType = null;
|
||||
|
||||
/** @var string */
|
||||
public $lastError = '';
|
||||
|
||||
/** @var array */
|
||||
public $shpData = [];
|
||||
/** @var array */
|
||||
public $dbfData = [];
|
||||
|
||||
public function __construct(int $shapeType)
|
||||
{
|
||||
$this->shapeType = $shapeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads record from files.
|
||||
*
|
||||
* @param ShapeFile $shapeFile The ShapeFile object
|
||||
* @param resource $shpFile Opened SHP file (by reference)
|
||||
* @param resource $dbfFile Opened DBF file (by reference)
|
||||
*/
|
||||
public function loadFromFile(ShapeFile &$shapeFile, &$shpFile, &$dbfFile): void
|
||||
{
|
||||
$this->shapeFile = $shapeFile;
|
||||
$this->shpFile = $shpFile;
|
||||
$this->dbfFile = $dbfFile;
|
||||
$this->loadHeaders();
|
||||
|
||||
/* No header read */
|
||||
if ($this->read === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
$this->loadNullRecord();
|
||||
break;
|
||||
case 1:
|
||||
$this->loadPointRecord();
|
||||
break;
|
||||
case 21:
|
||||
$this->loadPointMRecord();
|
||||
break;
|
||||
case 11:
|
||||
$this->loadPointZRecord();
|
||||
break;
|
||||
case 3:
|
||||
$this->loadPolyLineRecord();
|
||||
break;
|
||||
case 23:
|
||||
$this->loadPolyLineMRecord();
|
||||
break;
|
||||
case 13:
|
||||
$this->loadPolyLineZRecord();
|
||||
break;
|
||||
case 5:
|
||||
$this->loadPolygonRecord();
|
||||
break;
|
||||
case 25:
|
||||
$this->loadPolygonMRecord();
|
||||
break;
|
||||
case 15:
|
||||
$this->loadPolygonZRecord();
|
||||
break;
|
||||
case 8:
|
||||
$this->loadMultiPointRecord();
|
||||
break;
|
||||
case 28:
|
||||
$this->loadMultiPointMRecord();
|
||||
break;
|
||||
case 18:
|
||||
$this->loadMultiPointZRecord();
|
||||
break;
|
||||
default:
|
||||
$this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType));
|
||||
break;
|
||||
}
|
||||
|
||||
/* We need to skip rest of the record */
|
||||
while ($this->read < $this->size) {
|
||||
$this->loadData('V', 4);
|
||||
}
|
||||
|
||||
/* Check if we didn't read too much */
|
||||
if ($this->read !== $this->size) {
|
||||
$this->setError(sprintf('Failed to parse record, read=%d, size=%d', $this->read, $this->size));
|
||||
}
|
||||
|
||||
if (! ShapeFile::supportsDbase() || ! isset($this->dbfFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadDBFData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves record to files.
|
||||
*
|
||||
* @param resource $shpFile Opened SHP file
|
||||
* @param resource $dbfFile Opened DBF file
|
||||
* @param int $recordNumber Record number
|
||||
*/
|
||||
public function saveToFile(&$shpFile, &$dbfFile, int $recordNumber): void
|
||||
{
|
||||
$this->shpFile = $shpFile;
|
||||
$this->dbfFile = $dbfFile;
|
||||
$this->recordNumber = $recordNumber;
|
||||
$this->saveHeaders();
|
||||
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
// Nothing to save
|
||||
break;
|
||||
case 1:
|
||||
$this->savePointRecord();
|
||||
break;
|
||||
case 21:
|
||||
$this->savePointMRecord();
|
||||
break;
|
||||
case 11:
|
||||
$this->savePointZRecord();
|
||||
break;
|
||||
case 3:
|
||||
$this->savePolyLineRecord();
|
||||
break;
|
||||
case 23:
|
||||
$this->savePolyLineMRecord();
|
||||
break;
|
||||
case 13:
|
||||
$this->savePolyLineZRecord();
|
||||
break;
|
||||
case 5:
|
||||
$this->savePolygonRecord();
|
||||
break;
|
||||
case 25:
|
||||
$this->savePolygonMRecord();
|
||||
break;
|
||||
case 15:
|
||||
$this->savePolygonZRecord();
|
||||
break;
|
||||
case 8:
|
||||
$this->saveMultiPointRecord();
|
||||
break;
|
||||
case 28:
|
||||
$this->saveMultiPointMRecord();
|
||||
break;
|
||||
case 18:
|
||||
$this->saveMultiPointZRecord();
|
||||
break;
|
||||
default:
|
||||
$this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType));
|
||||
break;
|
||||
}
|
||||
|
||||
if (! ShapeFile::supportsDbase() || $this->dbfFile === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->saveDBFData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates DBF data to match header.
|
||||
*
|
||||
* @param array $header DBF structure header
|
||||
*/
|
||||
public function updateDBFInfo(array $header): void
|
||||
{
|
||||
$tmp = $this->dbfData;
|
||||
unset($this->dbfData);
|
||||
$this->dbfData = [];
|
||||
foreach ($header as $value) {
|
||||
$this->dbfData[$value[0]] = $tmp[$value[0]] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data.
|
||||
*
|
||||
* @param string $type type for unpack()
|
||||
* @param int $count number of bytes
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function loadData(string $type, int $count)
|
||||
{
|
||||
$data = $this->shapeFile->readSHP($count);
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->read += strlen($data);
|
||||
|
||||
return Util::loadData($type, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads metadata header from a file.
|
||||
*/
|
||||
private function loadHeaders(): void
|
||||
{
|
||||
$this->shapeType = false;
|
||||
$this->recordNumber = $this->loadData('N', 4);
|
||||
if ($this->recordNumber === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We read the length of the record
|
||||
$this->size = $this->loadData('N', 4);
|
||||
if ($this->size === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->size = ($this->size * 2) + 8;
|
||||
$this->shapeType = $this->loadData('V', 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves metadata header to a file.
|
||||
*/
|
||||
private function saveHeaders(): void
|
||||
{
|
||||
fwrite($this->shpFile, pack('N', $this->recordNumber));
|
||||
fwrite($this->shpFile, pack('N', $this->getContentLength()));
|
||||
fwrite($this->shpFile, pack('V', $this->shapeType));
|
||||
}
|
||||
|
||||
private function loadPoint(): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
$data['x'] = $this->loadData('d', 8);
|
||||
$data['y'] = $this->loadData('d', 8);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function loadPointM(): array
|
||||
{
|
||||
$data = $this->loadPoint();
|
||||
|
||||
$data['m'] = $this->loadData('d', 8);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function loadPointZ(): array
|
||||
{
|
||||
$data = $this->loadPoint();
|
||||
|
||||
$data['z'] = $this->loadData('d', 8);
|
||||
$data['m'] = $this->loadData('d', 8);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function savePoint(array $data): void
|
||||
{
|
||||
fwrite($this->shpFile, Util::packDouble($data['x']));
|
||||
fwrite($this->shpFile, Util::packDouble($data['y']));
|
||||
}
|
||||
|
||||
private function savePointM(array $data): void
|
||||
{
|
||||
fwrite($this->shpFile, Util::packDouble($data['x']));
|
||||
fwrite($this->shpFile, Util::packDouble($data['y']));
|
||||
fwrite($this->shpFile, Util::packDouble($data['m']));
|
||||
}
|
||||
|
||||
private function savePointZ(array $data): void
|
||||
{
|
||||
fwrite($this->shpFile, Util::packDouble($data['x']));
|
||||
fwrite($this->shpFile, Util::packDouble($data['y']));
|
||||
fwrite($this->shpFile, Util::packDouble($data['z']));
|
||||
fwrite($this->shpFile, Util::packDouble($data['m']));
|
||||
}
|
||||
|
||||
private function loadNullRecord(): void
|
||||
{
|
||||
$this->shpData = [];
|
||||
}
|
||||
|
||||
private function loadPointRecord(): void
|
||||
{
|
||||
$this->shpData = $this->loadPoint();
|
||||
}
|
||||
|
||||
private function loadPointMRecord(): void
|
||||
{
|
||||
$this->shpData = $this->loadPointM();
|
||||
}
|
||||
|
||||
private function loadPointZRecord(): void
|
||||
{
|
||||
$this->shpData = $this->loadPointZ();
|
||||
}
|
||||
|
||||
private function savePointRecord(): void
|
||||
{
|
||||
$this->savePoint($this->shpData);
|
||||
}
|
||||
|
||||
private function savePointMRecord(): void
|
||||
{
|
||||
$this->savePointM($this->shpData);
|
||||
}
|
||||
|
||||
private function savePointZRecord(): void
|
||||
{
|
||||
$this->savePointZ($this->shpData);
|
||||
}
|
||||
|
||||
private function loadBBox(): void
|
||||
{
|
||||
$this->shpData['xmin'] = $this->loadData('d', 8);
|
||||
$this->shpData['ymin'] = $this->loadData('d', 8);
|
||||
$this->shpData['xmax'] = $this->loadData('d', 8);
|
||||
$this->shpData['ymax'] = $this->loadData('d', 8);
|
||||
}
|
||||
|
||||
private function loadMultiPointRecord(): void
|
||||
{
|
||||
$this->shpData = [];
|
||||
$this->loadBBox();
|
||||
|
||||
$this->shpData['numpoints'] = $this->loadData('V', 4);
|
||||
|
||||
for ($i = 0; $i < $this->shpData['numpoints']; ++$i) {
|
||||
$this->shpData['points'][] = $this->loadPoint();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadMultiPointMZRecord(string $type): void
|
||||
{
|
||||
/* The m dimension is optional, depends on bounding box data */
|
||||
if ($type === 'm' && ! $this->shapeFile->hasMeasure()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->shpData[$type . 'min'] = $this->loadData('d', 8);
|
||||
$this->shpData[$type . 'max'] = $this->loadData('d', 8);
|
||||
|
||||
for ($i = 0; $i < $this->shpData['numpoints']; ++$i) {
|
||||
$this->shpData['points'][$i][$type] = $this->loadData('d', 8);
|
||||
}
|
||||
}
|
||||
|
||||
private function loadMultiPointMRecord(): void
|
||||
{
|
||||
$this->loadMultiPointRecord();
|
||||
|
||||
$this->loadMultiPointMZRecord('m');
|
||||
}
|
||||
|
||||
private function loadMultiPointZRecord(): void
|
||||
{
|
||||
$this->loadMultiPointRecord();
|
||||
|
||||
$this->loadMultiPointMZRecord('z');
|
||||
$this->loadMultiPointMZRecord('m');
|
||||
}
|
||||
|
||||
private function saveMultiPointRecord(): void
|
||||
{
|
||||
fwrite($this->shpFile, pack(
|
||||
'dddd',
|
||||
$this->shpData['xmin'],
|
||||
$this->shpData['ymin'],
|
||||
$this->shpData['xmax'],
|
||||
$this->shpData['ymax']
|
||||
));
|
||||
|
||||
fwrite($this->shpFile, pack('V', $this->shpData['numpoints']));
|
||||
|
||||
for ($i = 0; $i < $this->shpData['numpoints']; ++$i) {
|
||||
$this->savePoint($this->shpData['points'][$i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function saveMultiPointMZRecord(string $type): void
|
||||
{
|
||||
fwrite($this->shpFile, pack('dd', $this->shpData[$type . 'min'], $this->shpData[$type . 'max']));
|
||||
|
||||
for ($i = 0; $i < $this->shpData['numpoints']; ++$i) {
|
||||
fwrite($this->shpFile, Util::packDouble($this->shpData['points'][$i][$type]));
|
||||
}
|
||||
}
|
||||
|
||||
private function saveMultiPointMRecord(): void
|
||||
{
|
||||
$this->saveMultiPointRecord();
|
||||
|
||||
$this->saveMultiPointMZRecord('m');
|
||||
}
|
||||
|
||||
private function saveMultiPointZRecord(): void
|
||||
{
|
||||
$this->saveMultiPointRecord();
|
||||
|
||||
$this->saveMultiPointMZRecord('z');
|
||||
$this->saveMultiPointMZRecord('m');
|
||||
}
|
||||
|
||||
private function loadPolyLineRecord(): void
|
||||
{
|
||||
$this->shpData = [];
|
||||
$this->loadBBox();
|
||||
|
||||
$this->shpData['numparts'] = $this->loadData('V', 4);
|
||||
$this->shpData['numpoints'] = $this->loadData('V', 4);
|
||||
|
||||
$numparts = $this->shpData['numparts'];
|
||||
$numpoints = $this->shpData['numpoints'];
|
||||
|
||||
for ($i = 0; $i < $numparts; ++$i) {
|
||||
$this->shpData['parts'][$i] = $this->loadData('V', 4);
|
||||
}
|
||||
|
||||
$part = 0;
|
||||
for ($i = 0; $i < $numpoints; ++$i) {
|
||||
if ($part + 1 < $numparts && $i === $this->shpData['parts'][$part + 1]) {
|
||||
++$part;
|
||||
}
|
||||
|
||||
if (! isset($this->shpData['parts'][$part]['points'])
|
||||
|| ! is_array($this->shpData['parts'][$part]['points'])
|
||||
) {
|
||||
$this->shpData['parts'][$part] = ['points' => []];
|
||||
}
|
||||
|
||||
$this->shpData['parts'][$part]['points'][] = $this->loadPoint();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadPolyLineMZRecord(string $type): void
|
||||
{
|
||||
/* The m dimension is optional, depends on bounding box data */
|
||||
if ($type === 'm' && ! $this->shapeFile->hasMeasure()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->shpData[$type . 'min'] = $this->loadData('d', 8);
|
||||
$this->shpData[$type . 'max'] = $this->loadData('d', 8);
|
||||
|
||||
$numparts = $this->shpData['numparts'];
|
||||
$numpoints = $this->shpData['numpoints'];
|
||||
|
||||
$part = 0;
|
||||
for ($i = 0; $i < $numpoints; ++$i) {
|
||||
if ($part + 1 < $numparts && $i === $this->shpData['parts'][$part + 1]) {
|
||||
++$part;
|
||||
}
|
||||
|
||||
$this->shpData['parts'][$part]['points'][$i][$type] = $this->loadData('d', 8);
|
||||
}
|
||||
}
|
||||
|
||||
private function loadPolyLineMRecord(): void
|
||||
{
|
||||
$this->loadPolyLineRecord();
|
||||
|
||||
$this->loadPolyLineMZRecord('m');
|
||||
}
|
||||
|
||||
private function loadPolyLineZRecord(): void
|
||||
{
|
||||
$this->loadPolyLineRecord();
|
||||
|
||||
$this->loadPolyLineMZRecord('z');
|
||||
$this->loadPolyLineMZRecord('m');
|
||||
}
|
||||
|
||||
private function savePolyLineRecord(): void
|
||||
{
|
||||
fwrite($this->shpFile, pack(
|
||||
'dddd',
|
||||
$this->shpData['xmin'],
|
||||
$this->shpData['ymin'],
|
||||
$this->shpData['xmax'],
|
||||
$this->shpData['ymax']
|
||||
));
|
||||
|
||||
fwrite($this->shpFile, pack('VV', $this->shpData['numparts'], $this->shpData['numpoints']));
|
||||
|
||||
$partIndex = 0;
|
||||
for ($i = 0; $i < $this->shpData['numparts']; ++$i) {
|
||||
fwrite($this->shpFile, pack('V', $partIndex));
|
||||
$partIndex += count($this->shpData['parts'][$i]['points']);
|
||||
}
|
||||
|
||||
foreach ($this->shpData['parts'] as $partData) {
|
||||
foreach ($partData['points'] as $pointData) {
|
||||
$this->savePoint($pointData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function savePolyLineMZRecord(string $type): void
|
||||
{
|
||||
fwrite($this->shpFile, pack('dd', $this->shpData[$type . 'min'], $this->shpData[$type . 'max']));
|
||||
|
||||
foreach ($this->shpData['parts'] as $partData) {
|
||||
foreach ($partData['points'] as $pointData) {
|
||||
fwrite($this->shpFile, Util::packDouble($pointData[$type]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function savePolyLineMRecord(): void
|
||||
{
|
||||
$this->savePolyLineRecord();
|
||||
|
||||
$this->savePolyLineMZRecord('m');
|
||||
}
|
||||
|
||||
private function savePolyLineZRecord(): void
|
||||
{
|
||||
$this->savePolyLineRecord();
|
||||
|
||||
$this->savePolyLineMZRecord('z');
|
||||
$this->savePolyLineMZRecord('m');
|
||||
}
|
||||
|
||||
private function loadPolygonRecord(): void
|
||||
{
|
||||
$this->loadPolyLineRecord();
|
||||
}
|
||||
|
||||
private function loadPolygonMRecord(): void
|
||||
{
|
||||
$this->loadPolyLineMRecord();
|
||||
}
|
||||
|
||||
private function loadPolygonZRecord(): void
|
||||
{
|
||||
$this->loadPolyLineZRecord();
|
||||
}
|
||||
|
||||
private function savePolygonRecord(): void
|
||||
{
|
||||
$this->savePolyLineRecord();
|
||||
}
|
||||
|
||||
private function savePolygonMRecord(): void
|
||||
{
|
||||
$this->savePolyLineMRecord();
|
||||
}
|
||||
|
||||
private function savePolygonZRecord(): void
|
||||
{
|
||||
$this->savePolyLineZRecord();
|
||||
}
|
||||
|
||||
private function adjustBBox(array $point): void
|
||||
{
|
||||
// Adjusts bounding box based on point
|
||||
$directions = [
|
||||
'x',
|
||||
'y',
|
||||
'z',
|
||||
'm',
|
||||
];
|
||||
foreach ($directions as $direction) {
|
||||
if (! isset($point[$direction])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$min = $direction . 'min';
|
||||
$max = $direction . 'max';
|
||||
if (! isset($this->shpData[$min]) || ($this->shpData[$min] > $point[$direction])) {
|
||||
$this->shpData[$min] = $point[$direction];
|
||||
}
|
||||
|
||||
if (isset($this->shpData[$max]) && ($this->shpData[$max] >= $point[$direction])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->shpData[$max] = $point[$direction];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets dimension to 0 if not set.
|
||||
*
|
||||
* @param array $point Point to check
|
||||
* @param string $dimension Dimension to check
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function fixPoint(array $point, string $dimension): array
|
||||
{
|
||||
if (! isset($point[$dimension])) {
|
||||
$point[$dimension] = 0.0; // no_value
|
||||
}
|
||||
|
||||
return $point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust point and bounding box when adding point.
|
||||
*
|
||||
* @param array $point Point data
|
||||
*
|
||||
* @return array Fixed point data
|
||||
*/
|
||||
private function adjustPoint(array $point): array
|
||||
{
|
||||
$type = $this->shapeType / 10;
|
||||
if ($type >= 2) {
|
||||
$point = $this->fixPoint($point, 'm');
|
||||
} elseif ($type >= 1) {
|
||||
$point = $this->fixPoint($point, 'z');
|
||||
$point = $this->fixPoint($point, 'm');
|
||||
}
|
||||
|
||||
return $point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds point to a record.
|
||||
*
|
||||
* @param array $point Point data
|
||||
* @param int $partIndex Part index
|
||||
*/
|
||||
public function addPoint(array $point, int $partIndex = 0): void
|
||||
{
|
||||
$point = $this->adjustPoint($point);
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
//Don't add anything
|
||||
return;
|
||||
case 1:
|
||||
case 11:
|
||||
case 21:
|
||||
//Substitutes the value of the current point
|
||||
$this->shpData = $point;
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
case 13:
|
||||
case 15:
|
||||
case 23:
|
||||
case 25:
|
||||
//Adds a new point to the selected part
|
||||
$this->shpData['parts'][$partIndex]['points'][] = $point;
|
||||
$this->shpData['numparts'] = count($this->shpData['parts']);
|
||||
$this->shpData['numpoints'] = 1 + ($this->shpData['numpoints'] ?? 0);
|
||||
break;
|
||||
case 8:
|
||||
case 18:
|
||||
case 28:
|
||||
//Adds a new point
|
||||
$this->shpData['points'][] = $point;
|
||||
$this->shpData['numpoints'] = 1 + ($this->shpData['numpoints'] ?? 0);
|
||||
break;
|
||||
default:
|
||||
$this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->adjustBBox($point);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes point from a record.
|
||||
*
|
||||
* @param int $pointIndex Point index
|
||||
* @param int $partIndex Part index
|
||||
*/
|
||||
public function deletePoint(int $pointIndex = 0, int $partIndex = 0): void
|
||||
{
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
//Don't delete anything
|
||||
break;
|
||||
case 1:
|
||||
case 11:
|
||||
case 21:
|
||||
//Sets the value of the point to zero
|
||||
$this->shpData['x'] = 0.0;
|
||||
$this->shpData['y'] = 0.0;
|
||||
if (in_array($this->shapeType, [11, 21])) {
|
||||
$this->shpData['m'] = 0.0;
|
||||
}
|
||||
|
||||
if (in_array($this->shapeType, [11])) {
|
||||
$this->shpData['z'] = 0.0;
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
case 13:
|
||||
case 15:
|
||||
case 23:
|
||||
case 25:
|
||||
//Deletes the point from the selected part, if exists
|
||||
if (isset($this->shpData['parts'][$partIndex])
|
||||
&& isset($this->shpData['parts'][$partIndex]['points'][$pointIndex])
|
||||
) {
|
||||
$count = count($this->shpData['parts'][$partIndex]['points']) - 1;
|
||||
for ($i = $pointIndex; $i < $count; ++$i) {
|
||||
$point = $this->shpData['parts'][$partIndex]['points'][$i + 1];
|
||||
$this->shpData['parts'][$partIndex]['points'][$i] = $point;
|
||||
}
|
||||
|
||||
$count = count($this->shpData['parts'][$partIndex]['points']) - 1;
|
||||
unset($this->shpData['parts'][$partIndex]['points'][$count]);
|
||||
|
||||
$this->shpData['numparts'] = count($this->shpData['parts']);
|
||||
--$this->shpData['numpoints'];
|
||||
}
|
||||
|
||||
break;
|
||||
case 8:
|
||||
case 18:
|
||||
case 28:
|
||||
//Deletes the point, if exists
|
||||
if (isset($this->shpData['points'][$pointIndex])) {
|
||||
$count = count($this->shpData['points']) - 1;
|
||||
for ($i = $pointIndex; $i < $count; ++$i) {
|
||||
$this->shpData['points'][$i] = $this->shpData['points'][$i + 1];
|
||||
}
|
||||
|
||||
unset($this->shpData['points'][count($this->shpData['points']) - 1]);
|
||||
|
||||
--$this->shpData['numpoints'];
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
$this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns length of content.
|
||||
*/
|
||||
public function getContentLength(): ?int
|
||||
{
|
||||
// The content length for a record is the length of the record contents section measured in 16-bit words.
|
||||
// one coordinate makes 4 16-bit words (64 bit double)
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
$result = 0;
|
||||
break;
|
||||
case 1:
|
||||
$result = 10;
|
||||
break;
|
||||
case 21:
|
||||
$result = 10 + 4;
|
||||
break;
|
||||
case 11:
|
||||
$result = 10 + 8;
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
$count = count($this->shpData['parts']);
|
||||
$result = 22 + 2 * $count;
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$result += 8 * count($this->shpData['parts'][$i]['points']);
|
||||
}
|
||||
|
||||
break;
|
||||
case 23:
|
||||
case 25:
|
||||
$count = count($this->shpData['parts']);
|
||||
$result = 22 + (2 * 4) + 2 * $count;
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$result += (8 + 4) * count($this->shpData['parts'][$i]['points']);
|
||||
}
|
||||
|
||||
break;
|
||||
case 13:
|
||||
case 15:
|
||||
$count = count($this->shpData['parts']);
|
||||
$result = 22 + (4 * 4) + 2 * $count;
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$result += (8 + 8) * count($this->shpData['parts'][$i]['points']);
|
||||
}
|
||||
|
||||
break;
|
||||
case 8:
|
||||
$result = 20 + 8 * count($this->shpData['points']);
|
||||
break;
|
||||
case 28:
|
||||
$result = 20 + (2 * 4) + (8 + 4) * count($this->shpData['points']);
|
||||
break;
|
||||
case 18:
|
||||
$result = 20 + (4 * 4) + (8 + 8) * count($this->shpData['points']);
|
||||
break;
|
||||
default:
|
||||
$result = null;
|
||||
$this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType));
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function loadDBFData(): void
|
||||
{
|
||||
$this->dbfData = @dbase_get_record_with_names($this->dbfFile, $this->recordNumber);
|
||||
unset($this->dbfData['deleted']);
|
||||
}
|
||||
|
||||
private function saveDBFData(): void
|
||||
{
|
||||
if (count($this->dbfData) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->dbfData['deleted']);
|
||||
if ($this->recordNumber <= dbase_numrecords($this->dbfFile)) {
|
||||
if (! dbase_replace_record($this->dbfFile, array_values($this->dbfData), $this->recordNumber)) {
|
||||
$this->setError('I wasn\'t possible to update the information in the DBF file.');
|
||||
}
|
||||
} else {
|
||||
if (! dbase_add_record($this->dbfFile, array_values($this->dbfData))) {
|
||||
$this->setError('I wasn\'t possible to add the information to the DBF file.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets error message.
|
||||
*/
|
||||
public function setError(string $error): void
|
||||
{
|
||||
$this->lastError = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shape name.
|
||||
*/
|
||||
public function getShapeName(): string
|
||||
{
|
||||
return Util::nameShape($this->shapeType);
|
||||
}
|
||||
}
|
126
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/src/Util.php
vendored
Normal file
126
admin/phpMyAdmin/vendor/phpmyadmin/shapefile/src/Util.php
vendored
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpMyAdmin ShapeFile library
|
||||
* <https://github.com/phpmyadmin/shapefile/>.
|
||||
*
|
||||
* Copyright 2006-2007 Ovidio <ovidio AT users.sourceforge.net>
|
||||
* Copyright 2016 - 2017 Michal Čihař <michal@cihar.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can download one from
|
||||
* https://www.gnu.org/copyleft/gpl.html.
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\ShapeFile;
|
||||
|
||||
use function current;
|
||||
use function pack;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
use function unpack;
|
||||
|
||||
class Util
|
||||
{
|
||||
/** @var bool|null */
|
||||
private static $littleEndian = null;
|
||||
|
||||
/** @var array */
|
||||
private static $shapeNames = [
|
||||
0 => 'Null Shape',
|
||||
1 => 'Point',
|
||||
3 => 'PolyLine',
|
||||
5 => 'Polygon',
|
||||
8 => 'MultiPoint',
|
||||
11 => 'PointZ',
|
||||
13 => 'PolyLineZ',
|
||||
15 => 'PolygonZ',
|
||||
18 => 'MultiPointZ',
|
||||
21 => 'PointM',
|
||||
23 => 'PolyLineM',
|
||||
25 => 'PolygonM',
|
||||
28 => 'MultiPointM',
|
||||
31 => 'MultiPatch',
|
||||
];
|
||||
|
||||
/**
|
||||
* Reads data.
|
||||
*
|
||||
* @param string $type type for unpack()
|
||||
* @param string|false $data Data to process
|
||||
*
|
||||
* @return mixed|false
|
||||
*/
|
||||
public static function loadData(string $type, $data)
|
||||
{
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strlen($data) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tmp = unpack($type, $data);
|
||||
|
||||
return $tmp === false ? $tmp : current($tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes endianity.
|
||||
*
|
||||
* @param string $binValue Binary value
|
||||
*/
|
||||
public static function swap(string $binValue): string
|
||||
{
|
||||
$result = $binValue[strlen($binValue) - 1];
|
||||
for ($i = strlen($binValue) - 2; $i >= 0; --$i) {
|
||||
$result .= $binValue[$i];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes double value to correct endianity.
|
||||
*
|
||||
* @param float $value Value to pack
|
||||
*/
|
||||
public static function packDouble(float $value): string
|
||||
{
|
||||
$bin = pack('d', (float) $value);
|
||||
|
||||
if (self::$littleEndian === null) {
|
||||
self::$littleEndian = (pack('L', 1) === pack('V', 1));
|
||||
}
|
||||
|
||||
if (self::$littleEndian) {
|
||||
return $bin;
|
||||
}
|
||||
|
||||
return self::swap($bin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shape name.
|
||||
*/
|
||||
public static function nameShape(int $type): string
|
||||
{
|
||||
if (isset(self::$shapeNames[$type])) {
|
||||
return self::$shapeNames[$type];
|
||||
}
|
||||
|
||||
return sprintf('Shape %d', $type);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue