You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-38Lines changed: 84 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -13,22 +13,29 @@ Please check the documentation for your MySQL version. MySQL's Extension for Spa
13
13
**Versions**
14
14
15
15
-`1.x.x`: MySQL 5.6 (also supports MySQL 5.5 but not all spatial analysis functions)
16
-
-`2.x.x`: MySQL 5.7 and 8.0
16
+
-`2.x.x`: MySQL 5.7
17
+
-**`3.x.x`: MySQL 8.0 with SRID support (Current branch)**
17
18
18
19
This package also works with MariaDB. Please refer to the [MySQL/MariaDB Spatial Support Matrix](https://mariadb.com/kb/en/library/mysqlmariadb-spatial-support-matrix/) for compatibility.
// // Add a Point spatial data field named location with SRID 4326
98
+
// $table->point('location', 4326)->nullable();
99
+
// // Add a Polygon spatial data field named area with SRID 4326
100
+
// $table->polygon('area', 4326)->nullable();
101
+
// $table->timestamps();
102
+
// });
83
103
}
84
104
85
105
/**
@@ -158,11 +178,37 @@ $place1->area = new Polygon([new LineString([
158
178
new Point(40.74894149554006, -73.98615270853043)
159
179
])]);
160
180
$place1->save();
181
+
```
182
+
183
+
Or if your database fields were created with a specific SRID:
184
+
185
+
```php
186
+
use Grimzy\LaravelMysqlSpatial\Types\Point;
187
+
use Grimzy\LaravelMysqlSpatial\Types\Polygon;
188
+
use Grimzy\LaravelMysqlSpatial\Types\LineString;
189
+
190
+
$place1 = new Place();
191
+
$place1->name = 'Empire State Building';
161
192
162
-
$place1->area = new Polygon();
193
+
// saving a point with SRID 4326 (WGS84 spheroid)
194
+
$place1->location = new Point(40.7484404, -73.9878441, 4326); // (lat, lng, srid)
195
+
$place1->save();
163
196
197
+
// saving a polygon with SRID 4326 (WGS84 spheroid)
198
+
$place1->area = new Polygon([new LineString([
199
+
new Point(40.74894149554006, -73.98615270853043),
200
+
new Point(40.74848633046773, -73.98648262023926),
201
+
new Point(40.747925497790725, -73.9851602911949),
202
+
new Point(40.74837050671544, -73.98482501506805),
203
+
new Point(40.74894149554006, -73.98615270853043)
204
+
])], 4326);
205
+
$place1->save();
164
206
```
165
207
208
+
> **Note**: When saving collection Geometries (`LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, and `GeometryCollection`), only the top-most geometry should have an SRID set in the constructor.
209
+
>
210
+
> In the example above, when creating a `new Polygon()`, we only set the SRID on the `Polygon` and use the default for the `LineString` and the `Point` objects.
|`Polygon(LineString[])`*([exterior and interior boundaries](https://dev.mysql.com/doc/refman/8.0/en/gis-class-polygon.html))*|[Polygon](https://dev.mysql.com/doc/refman/8.0/en/gis-class-polygon.html)|
Check out the [Class diagram](https://user-images.githubusercontent.com/1837678/30788608-a5afd894-a16c-11e7-9a51-0a08b331d4c4.png).
189
235
@@ -193,7 +239,7 @@ In order for your Eloquent Model to handle the Geometry classes, it must use the
193
239
194
240
#### IteratorAggregate and ArrayAccess
195
241
196
-
The "composite" Geometries (`LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, and `GeometryCollection`) implement [`IteratorAggregate`](http://php.net/manual/en/class.iteratoraggregate.php) and [`ArrayAccess`](http://php.net/manual/en/class.arrayaccess.php); making it easy to perform Iterator and Array operations. For example:
242
+
The collection Geometries (`LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, and `GeometryCollection`) implement [`IteratorAggregate`](http://php.net/manual/en/class.iteratoraggregate.php) and [`ArrayAccess`](http://php.net/manual/en/class.arrayaccess.php); making it easy to perform Iterator and Array operations. For example:
197
243
198
244
```php
199
245
$polygon = $multipolygon[10]; // ArrayAccess
@@ -207,10 +253,10 @@ for($polygon as $i => $linestring) {
207
253
208
254
#### Helpers
209
255
210
-
##### From/To Well Known Text ([WKT](https://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html#gis-wkt-format))
256
+
##### From/To Well Known Text ([WKT](https://dev.mysql.com/doc/refman/8.0/en/gis-data-formats.html#gis-wkt-format))
*Note that behavior and availability of MySQL spatial analysis functions differs in each MySQL version (cf. [documentation](https://dev.mysql.com/doc/refman/5.7/en/spatial-function-reference.html)).*
332
+
*Note that behavior and availability of MySQL spatial analysis functions differs in each MySQL version (cf. [documentation](https://dev.mysql.com/doc/refman/8.0/en/spatial-function-reference.html)).*
287
333
288
334
## Migrations
289
335
@@ -300,16 +346,16 @@ class CreatePlacesTable extends Migration {
300
346
301
347
### Columns
302
348
303
-
Available [MySQL Spatial Types](https://dev.mysql.com/doc/refman/5.7/en/spatial-datatypes.html) migration blueprints:
349
+
Available [MySQL Spatial Types](https://dev.mysql.com/doc/refman/8.0/en/spatial-type-overview.html) migration blueprints:
304
350
305
-
-`$table->geometry('column_name')`
306
-
-`$table->point('column_name')`
307
-
-`$table->lineString('column_name')`
308
-
-`$table->polygon('column_name')`
309
-
-`$table->multiPoint('column_name')`
310
-
-`$table->multiLineString('column_name')`
311
-
-`$table->multiPolygon('column_name')`
312
-
-`$table->geometryCollection('column_name')`
351
+
-`$table->geometry(string $column_name, int $srid = 0)`
352
+
-`$table->point(string $column_name, int $srid = 0)`
353
+
-`$table->lineString(string $column_name, int $srid = 0)`
354
+
-`$table->polygon(string $column_name, int $srid = 0)`
355
+
-`$table->multiPoint(string $column_name, int $srid = 0)`
356
+
-`$table->multiLineString(string $column_name, int $srid = 0)`
357
+
-`$table->multiPolygon(string $column_name, int $srid = 0)`
358
+
-`$table->geometryCollection(string $column_name, int $srid = 0)`
313
359
314
360
### Spatial indexes
315
361
@@ -318,9 +364,9 @@ You can add or drop spatial indexes in your migrations with the `spatialIndex` a
318
364
-`$table->spatialIndex('column_name')`
319
365
-`$table->dropSpatialIndex(['column_name'])` or `$table->dropSpatialIndex('index_name')`
320
366
321
-
Note about spatial indexes from the [MySQL documentation](https://dev.mysql.com/doc/refman/5.7/en/creating-spatial-indexes.html):
367
+
Note about spatial indexes from the [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/creating-spatial-indexes.html):
322
368
323
-
> For [`MyISAM`](https://dev.mysql.com/doc/refman/5.7/en/myisam-storage-engine.html) and (as of MySQL 5.7.5) `InnoDB` tables, MySQL can create spatial indexes using syntax similar to that for creating regular indexes, but using the `SPATIAL` keyword. Columns in spatial indexes must be declared `NOT NULL`.
369
+
> For [`MyISAM`](https://dev.mysql.com/doc/refman/8.0/en/myisam-storage-engine.html) and (as of MySQL 5.7.5) `InnoDB` tables, MySQL can create spatial indexes using syntax similar to that for creating regular indexes, but using the `SPATIAL` keyword. Columns in spatial indexes must be declared `NOT NULL`.
324
370
325
371
Also please read this [**important note**](https://laravel.com/docs/5.5/migrations#indexes) regarding Index Lengths in the Laravel 5.6 documentation.
326
372
@@ -381,18 +427,18 @@ class UpdatePlacesTable extends Migration
381
427
## Tests
382
428
383
429
```shell
384
-
composer test
430
+
$ composer test
385
431
# or
386
-
composer test:unit
387
-
composer test:integration
432
+
$ composer test:unit
433
+
$ composer test:integration
388
434
```
389
435
390
436
Integration tests require a running MySQL database. If you have Docker installed, you can start easily start one:
0 commit comments