Library containing value objects to represent geographical information, parsers to turn user input into such value objects, and formatters to turn them back into user consumable representations.
It is part of the DataValues set of libraries.
On Packagist:
The recommended way to use this library is via Composer.
To add this package as a local, per-project dependency to your project, simply add a
dependency on data-values/geo
to your project's composer.json
file.
Here is a minimal example of a composer.json
file that just defines a dependency on
version 1.0 of this package:
{
"require": {
"data-values/geo": "1.0.*"
}
}
Get the code of this package, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. Then take care of autoloading the classes defined in the src directory.
These are simple value objects. They all implement the DataValues\DataValue
interface.
LatLongValue
- Object representing a geographic point specified by latitude and longitude.GlobeCoordinateValue
- Geographical coordinate with precision and globe.
These turn value objects into string representations.
They all implement the ValueFormatters\ValueFormatter
interface.
GeoCoordinateFormatter
- Formats a LatLongValue into float, decimal minute, decimal degree or degree minute second notation. Both directional and non-directional notation are supported. Directional labels, latitude-longitude separator and precision can be specified.GlobeCoordinateFormatter
- Formats a GlobeCoordinateValue.
These turn string representations into value objects.
They all implement the ValueParsers\ValueParser
interface.
Simple parsers:
DdCoordinateParser
- Parses decimal degree coordinates into LatLongValue objects.DmCoordinateParser
- Parses decimal minute coordinates into LatLongValue objects.DmsCoordinateParser
- Parses degree minute second coordinates into LatLongValue objects.FloatCoordinateParser
- Parses float coordinates into LatLongValue objects.
Composite parsers:
GeoCoordinateParser
- Facade for DdCoordinateParser, DmCoordinateParser, DmsCoordinateParser and FloatCoordinateParser. Parses a coordinate in any of the notations supported by these parsers into a LatLongValue object. Both directional and non-directional notation are supported. Directional labels and the latitude-longitude separator can be specified.GlobeCoordinateParser
- Parses coordinates into GlobeCoordinateValue objects.
This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these tests using the PHPUnit configuration file found in the root directory. The tests can also be run via TravisCI, as a TravisCI configuration file is also provided in the root directory.
DataValues Geo has been written by the Wikidata team, as [Wikimedia Germany] (https://wikimedia.de) employees for the Wikidata project.
It is based upon and contains a lot of code written by [Jeroen De Dauw] (https://github.com/JeroenDeDauw) for the Maps and Semantic MediaWiki projects.
- Add fall back to default on invalid precision to more places.
- Fall back to default on invalid precision instead of dividing by zero.
- Precision detection in
GlobeCoordinateParser
now has a lower bound of 0.00000001°
- Removed remaining uses of class aliases from messages and comments
- Fixed some types in documentation
- Made the component installable with DataValues 1.x
GeoCoordinateFormatter
now supports precision in degreesGlobeCoordinateFormatter
now passes the globe precision to theGeoCoordinateFormatter
it uses- Introduced
FORMAT_NAME
class constants on ValueParsers in order to use them as expectedFormat - Changed ValueParsers to pass rawValue and expectedFormat arguments when constructing a
ParseException
- All classes and interfaces have been moved into the
DataValues\Geo
namespaceDataValues\LatLongValue
has been left as deprecated aliasDataValues\GlobeCoordinateValue
has been left as deprecated alias
- Globe in
GlobeCoordinateValue
now defaults tohttp://www.wikidata.org/entity/Q2
- Removed deprecated
GeoCoordinateValue
- Added
GlobeMath
- Added support for different levels of spacing in GeoCoordinateFormatter
- Added support for direction notation to GeoCoordinateFormatter
- Decreased complexity of GeoCoordinateFormatter
- Decreased complexity and coupling of GeoCoordinateFormatterTest
Initial release with these features:
- LatLongValue
- GlobeCoordinateValue
- GeoCoordinateFormatter
- GlobeCoordinateFormatter
- DdCoordinateParser
- DmCoordinateParser
- DmsCoordinateParser
- FloatCoordinateParser
- GeoCoordinateParser
- GlobeCoordinateParser