Download the PHP package nashgao/hyperf-mysql-spatial without Composer
On this page you can find all versions of the php package nashgao/hyperf-mysql-spatial. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nashgao/hyperf-mysql-spatial
More information about nashgao/hyperf-mysql-spatial
Files in nashgao/hyperf-mysql-spatial
Package hyperf-mysql-spatial
Short Description MySQL spatial data types extension for Hyperf.
License MIT
Informations about the package hyperf-mysql-spatial
Hyperf MySQL Spatial extension
Spatial data type support for hyperf/database
Transplanted from grimzy/laravel-mysql-spatial
Installation
Add the package using composer:
Then edit the model you just created. It must use the SpatialTrait
and define an array called $spatialFields
with the name of the MySQL Spatial Data field(s) created in the migration:
Saving a model
Or if your database fields were created with a specific SRID:
Note: When saving collection Geometries (
LineString
,Polygon
,MultiPoint
,MultiLineString
, andGeometryCollection
), only the top-most geometry should have an SRID set in the constructor.In the example above, when creating a
new Polygon()
, we only set the SRID on thePolygon
and use the default for theLineString
and thePoint
objects.
Retrieving a model
Geometry classes
Available Geometry classes
Nashgao\HyperfMySQLSpatial\Types | OpenGIS Class |
---|---|
Point($lat, $lng, $srid = 0) |
Point |
MultiPoint(Point[], $srid = 0) |
MultiPoint |
LineString(Point[], $srid = 0) |
LineString |
MultiLineString(LineString[], $srid = 0) |
MultiLineString |
Polygon(LineString[], $srid = 0) (exterior and interior boundaries) |
Polygon |
MultiPolygon(Polygon[], $srid = 0) |
MultiPolygon |
GeometryCollection(Geometry[], $srid = 0) |
GeometryCollection |
Check out the Class diagram.
Using Geometry classes
In order for your Eloquent Model to handle the Geometry classes, it must use the Nashgao\HyperfMySQLSpatial\Eloquent\SpatialTrait
trait and define a protected
property $spatialFields
as an array of MySQL Spatial Data Type column names (example in Quickstart).
IteratorAggregate and ArrayAccess
The collection Geometries (LineString
, Polygon
, MultiPoint
, MultiLineString
, and GeometryCollection
) implement IteratorAggregate
and ArrayAccess
; making it easy to perform Iterator and Array operations. For example:
Helpers
From/To Well Known Text (WKT)
From/To String
From/To JSON (GeoJSON)
The Geometry classes implement JsonSerializable
and Illuminate\Contracts\Support\Jsonable
to help serialize into GeoJSON:
To deserialize a GeoJSON string into a Geometry class, you can use Geometry::fromJson($json_string)
:
Scopes: Spatial analysis functions
Spatial analysis functions are implemented using Eloquent Local Scopes.
Available scopes:
distance($geometryColumn, $geometry, $distance)
distanceExcludingSelf($geometryColumn, $geometry, $distance)
distanceSphere($geometryColumn, $geometry, $distance)
distanceSphereExcludingSelf($geometryColumn, $geometry, $distance)
comparison($geometryColumn, $geometry, $relationship)
within($geometryColumn, $polygon)
crosses($geometryColumn, $geometry)
contains($geometryColumn, $geometry)
disjoint($geometryColumn, $geometry)
equals($geometryColumn, $geometry)
intersects($geometryColumn, $geometry)
overlaps($geometryColumn, $geometry)
doesTouch($geometryColumn, $geometry)
orderBySpatial($geometryColumn, $geometry, $orderFunction, $direction = 'asc')
orderByDistance($geometryColumn, $geometry, $direction = 'asc')
orderByDistanceSphere($geometryColumn, $geometry, $direction = 'asc')
Note that behavior and availability of MySQL spatial analysis functions differs in each MySQL version (cf. documentation).
Contributing
Recommendations and pull request are most welcome! Pull requests with tests are the best! There are still a lot of MySQL spatial functions to implement or creative ways to use spatial functions.
Credits
Originally inspired from njbarrett's Laravel postgis package.
Transplanted from grimzy/laravel-mysql-spatial
All versions of hyperf-mysql-spatial with dependencies
hyperf/database Version ~3.1
hyperf/db-connection Version ~3.1
geo-io/wkb-parser Version dev-main
geo-io/interface Version dev-main
jmikola/geojson Version ^1.0
ext-pdo Version *