@@ -22,11 +22,11 @@ |
||
| 22 | 22 | class SpatialServiceProvider extends DatabaseServiceProvider |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Register the service provider. |
|
| 27 | - * |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 25 | + /** |
|
| 26 | + * Register the service provider. |
|
| 27 | + * |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | 30 | public function register() |
| 31 | 31 | { |
| 32 | 32 | // The connection factory is used to create the actual connection instances on |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | * protected $spatialFields = []; |
| 45 | 45 | */ |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | 50 | public $geometries = []; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | 55 | protected $stRelations = [ |
| 56 | 56 | 'Within', |
| 57 | 57 | 'Crosses', |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * Create a new Eloquent query builder for the model. |
| 68 | 68 | * |
| 69 | 69 | * @param \Illuminate\Database\Query\Builder $query |
| 70 | - * |
|
| 70 | + * |
|
| 71 | 71 | * @return \LaravelSpatial\Eloquent\Builder |
| 72 | 72 | */ |
| 73 | 73 | public function newEloquentBuilder($query) |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | return new Builder($query); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @inheritDoc |
|
| 80 | - */ |
|
| 78 | + /** |
|
| 79 | + * @inheritDoc |
|
| 80 | + */ |
|
| 81 | 81 | public function setRawAttributes(array $attributes, $sync = false) |
| 82 | 82 | { |
| 83 | 83 | $spatial_fields = $this->getSpatialFields(); |
@@ -104,39 +104,39 @@ discard block |
||
| 104 | 104 | return parent::setRawAttributes($attributes, $sync); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - public function getSpatialFields(): array |
|
| 107 | + /** |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + public function getSpatialFields(): array |
|
| 111 | 111 | { |
| 112 | 112 | if (property_exists($this, 'spatialFields') && !empty($this->spatialFields)) { |
| 113 | 113 | return $this->spatialFields; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - throw new SpatialFieldsNotDefinedException(__CLASS__ . ' has to define $spatialFields'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param \GeoJSON\Geometry\Geometry $value |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - protected function toWkt(Geometry $value): string |
|
| 125 | - { |
|
| 126 | - try { |
|
| 127 | - $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), false), 'json')->out('wkt'); |
|
| 128 | - } catch (Exception $e) { |
|
| 129 | - throw new SpatialParseException('Unable to data to geometry.', 0, $e); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return ($this->getConnection() instanceof PostgresConnection ? 'SRID=4326;' : '') . $wkt; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 137 | - * |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 116 | + throw new SpatialFieldsNotDefinedException(__CLASS__ . ' has to define $spatialFields'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param \GeoJSON\Geometry\Geometry $value |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + protected function toWkt(Geometry $value): string |
|
| 125 | + { |
|
| 126 | + try { |
|
| 127 | + $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), false), 'json')->out('wkt'); |
|
| 128 | + } catch (Exception $e) { |
|
| 129 | + throw new SpatialParseException('Unable to data to geometry.', 0, $e); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return ($this->getConnection() instanceof PostgresConnection ? 'SRID=4326;' : '') . $wkt; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 137 | + * |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | 140 | protected function performInsert(EloquentBuilder $query) |
| 141 | 141 | { |
| 142 | 142 | foreach ($this->attributes as $key => $value) { |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | return $insert; // Return the result of the parent insert |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @param $geometryColumn |
|
| 160 | - * |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - public function isColumnAllowed($geometryColumn): bool |
|
| 164 | - { |
|
| 158 | + /** |
|
| 159 | + * @param $geometryColumn |
|
| 160 | + * |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + public function isColumnAllowed($geometryColumn): bool |
|
| 164 | + { |
|
| 165 | 165 | if (!in_array($geometryColumn, $this->getSpatialFields(), true)) { |
| 166 | 166 | throw new SpatialFieldsNotDefinedException(sprintf('%s is not a valid spatial column.', $geometryColumn)); |
| 167 | 167 | } |
@@ -169,16 +169,16 @@ discard block |
||
| 169 | 169 | return true; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 174 | - * @param $geometryColumn |
|
| 175 | - * @param $geometry |
|
| 176 | - * @param $distance |
|
| 177 | - * |
|
| 178 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 179 | - */ |
|
| 180 | - public function scopeDistance($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 181 | - { |
|
| 172 | + /** |
|
| 173 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 174 | + * @param $geometryColumn |
|
| 175 | + * @param $geometry |
|
| 176 | + * @param $distance |
|
| 177 | + * |
|
| 178 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 179 | + */ |
|
| 180 | + public function scopeDistance($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 181 | + { |
|
| 182 | 182 | if ($this->isColumnAllowed($geometryColumn)) { |
| 183 | 183 | $geometryColumn .= $this->getConnection() instanceof PostgresConnection ? '::geometry' : ''; |
| 184 | 184 | $query->whereRaw("ST_Distance({$geometryColumn}, ST_GeomFromText(?)) <= ?", [ |
@@ -190,16 +190,16 @@ discard block |
||
| 190 | 190 | return $query; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 195 | - * @param $geometryColumn |
|
| 196 | - * @param $geometry |
|
| 197 | - * @param $distance |
|
| 198 | - * |
|
| 199 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 200 | - */ |
|
| 201 | - public function scopeDistanceExcludingSelf($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 202 | - { |
|
| 193 | + /** |
|
| 194 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 195 | + * @param $geometryColumn |
|
| 196 | + * @param $geometry |
|
| 197 | + * @param $distance |
|
| 198 | + * |
|
| 199 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 200 | + */ |
|
| 201 | + public function scopeDistanceExcludingSelf($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 202 | + { |
|
| 203 | 203 | if ($this->isColumnAllowed($geometryColumn)) { |
| 204 | 204 | $query = $this->scopeDistance($query, $geometryColumn, $geometry, $distance); |
| 205 | 205 | |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | return $query; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 217 | - * @param $geometryColumn |
|
| 218 | - * @param $geometry |
|
| 219 | - * |
|
| 220 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 221 | - */ |
|
| 222 | - public function scopeDistanceValue($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 223 | - { |
|
| 215 | + /** |
|
| 216 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 217 | + * @param $geometryColumn |
|
| 218 | + * @param $geometry |
|
| 219 | + * |
|
| 220 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 221 | + */ |
|
| 222 | + public function scopeDistanceValue($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 223 | + { |
|
| 224 | 224 | if ($this->isColumnAllowed($geometryColumn)) { |
| 225 | 225 | $columns = $query->getQuery()->columns; |
| 226 | 226 | |
@@ -237,16 +237,16 @@ discard block |
||
| 237 | 237 | return $query; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 242 | - * @param $geometryColumn |
|
| 243 | - * @param $geometry |
|
| 244 | - * @param $distance |
|
| 245 | - * |
|
| 246 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 247 | - */ |
|
| 248 | - public function scopeDistanceSphere($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 249 | - { |
|
| 240 | + /** |
|
| 241 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 242 | + * @param $geometryColumn |
|
| 243 | + * @param $geometry |
|
| 244 | + * @param $distance |
|
| 245 | + * |
|
| 246 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 247 | + */ |
|
| 248 | + public function scopeDistanceSphere($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 249 | + { |
|
| 250 | 250 | $distFunc = $this->getConnection() instanceof PostgresConnection ? 'ST_DistanceSphere' : 'ST_Distance_Sphere'; |
| 251 | 251 | |
| 252 | 252 | if ($this->isColumnAllowed($geometryColumn)) { |
@@ -260,16 +260,16 @@ discard block |
||
| 260 | 260 | return $query; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 265 | - * @param $geometryColumn |
|
| 266 | - * @param $geometry |
|
| 267 | - * @param $distance |
|
| 268 | - * |
|
| 269 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 270 | - */ |
|
| 271 | - public function scopeDistanceSphereExcludingSelf($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 272 | - { |
|
| 263 | + /** |
|
| 264 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 265 | + * @param $geometryColumn |
|
| 266 | + * @param $geometry |
|
| 267 | + * @param $distance |
|
| 268 | + * |
|
| 269 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 270 | + */ |
|
| 271 | + public function scopeDistanceSphereExcludingSelf($query, $geometryColumn, $geometry, $distance): EloquentBuilder |
|
| 272 | + { |
|
| 273 | 273 | $distFunc = $this->getConnection() instanceof PostgresConnection ? 'ST_DistanceSphere' : 'ST_Distance_Sphere'; |
| 274 | 274 | |
| 275 | 275 | if ($this->isColumnAllowed($geometryColumn)) { |
@@ -284,15 +284,15 @@ discard block |
||
| 284 | 284 | return $query; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 289 | - * @param $geometryColumn |
|
| 290 | - * @param $geometry |
|
| 291 | - * |
|
| 292 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 293 | - */ |
|
| 294 | - public function scopeDistanceSphereValue($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 295 | - { |
|
| 287 | + /** |
|
| 288 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 289 | + * @param $geometryColumn |
|
| 290 | + * @param $geometry |
|
| 291 | + * |
|
| 292 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 293 | + */ |
|
| 294 | + public function scopeDistanceSphereValue($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 295 | + { |
|
| 296 | 296 | $distFunc = $this->getConnection() instanceof PostgresConnection ? 'ST_DistanceSphere' : 'ST_Distance_Sphere'; |
| 297 | 297 | |
| 298 | 298 | if ($this->isColumnAllowed($geometryColumn)) { |
@@ -311,16 +311,16 @@ discard block |
||
| 311 | 311 | return $query; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 316 | - * @param $geometryColumn |
|
| 317 | - * @param $geometry |
|
| 318 | - * @param $relationship |
|
| 319 | - * |
|
| 320 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 321 | - */ |
|
| 322 | - public function scopeComparison($query, $geometryColumn, $geometry, $relationship): EloquentBuilder |
|
| 323 | - { |
|
| 314 | + /** |
|
| 315 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 316 | + * @param $geometryColumn |
|
| 317 | + * @param $geometry |
|
| 318 | + * @param $relationship |
|
| 319 | + * |
|
| 320 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 321 | + */ |
|
| 322 | + public function scopeComparison($query, $geometryColumn, $geometry, $relationship): EloquentBuilder |
|
| 323 | + { |
|
| 324 | 324 | if ($this->isColumnAllowed($geometryColumn)) { |
| 325 | 325 | $relationship = ucfirst(strtolower($relationship)); |
| 326 | 326 | |
@@ -337,99 +337,99 @@ discard block |
||
| 337 | 337 | return $query; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 342 | - * @param $geometryColumn |
|
| 343 | - * @param $polygon |
|
| 344 | - * |
|
| 345 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 346 | - */ |
|
| 347 | - public function scopeWithin($query, $geometryColumn, $polygon): EloquentBuilder |
|
| 348 | - { |
|
| 340 | + /** |
|
| 341 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 342 | + * @param $geometryColumn |
|
| 343 | + * @param $polygon |
|
| 344 | + * |
|
| 345 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 346 | + */ |
|
| 347 | + public function scopeWithin($query, $geometryColumn, $polygon): EloquentBuilder |
|
| 348 | + { |
|
| 349 | 349 | return $this->scopeComparison($query, $geometryColumn, $polygon, 'within'); |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 354 | - * @param $geometryColumn |
|
| 355 | - * @param $geometry |
|
| 356 | - * |
|
| 357 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 358 | - */ |
|
| 359 | - public function scopeCrosses($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 360 | - { |
|
| 352 | + /** |
|
| 353 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 354 | + * @param $geometryColumn |
|
| 355 | + * @param $geometry |
|
| 356 | + * |
|
| 357 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 358 | + */ |
|
| 359 | + public function scopeCrosses($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 360 | + { |
|
| 361 | 361 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'crosses'); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 366 | - * @param $geometryColumn |
|
| 367 | - * @param $geometry |
|
| 368 | - * |
|
| 369 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 370 | - */ |
|
| 371 | - public function scopeContains($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 372 | - { |
|
| 364 | + /** |
|
| 365 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 366 | + * @param $geometryColumn |
|
| 367 | + * @param $geometry |
|
| 368 | + * |
|
| 369 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 370 | + */ |
|
| 371 | + public function scopeContains($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 372 | + { |
|
| 373 | 373 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'contains'); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - /** |
|
| 377 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 378 | - * @param $geometryColumn |
|
| 379 | - * @param $geometry |
|
| 380 | - * |
|
| 381 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 382 | - */ |
|
| 383 | - public function scopeDisjoint($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 384 | - { |
|
| 376 | + /** |
|
| 377 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 378 | + * @param $geometryColumn |
|
| 379 | + * @param $geometry |
|
| 380 | + * |
|
| 381 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 382 | + */ |
|
| 383 | + public function scopeDisjoint($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 384 | + { |
|
| 385 | 385 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'disjoint'); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - /** |
|
| 389 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 390 | - * @param $geometryColumn |
|
| 391 | - * @param $geometry |
|
| 392 | - * |
|
| 393 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 394 | - */ |
|
| 395 | - public function scopeEquals($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 396 | - { |
|
| 388 | + /** |
|
| 389 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 390 | + * @param $geometryColumn |
|
| 391 | + * @param $geometry |
|
| 392 | + * |
|
| 393 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 394 | + */ |
|
| 395 | + public function scopeEquals($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 396 | + { |
|
| 397 | 397 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'equals'); |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - /** |
|
| 401 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 402 | - * @param $geometryColumn |
|
| 403 | - * @param $geometry |
|
| 404 | - * |
|
| 405 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 406 | - */ |
|
| 407 | - public function scopeIntersects($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 408 | - { |
|
| 400 | + /** |
|
| 401 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 402 | + * @param $geometryColumn |
|
| 403 | + * @param $geometry |
|
| 404 | + * |
|
| 405 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 406 | + */ |
|
| 407 | + public function scopeIntersects($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 408 | + { |
|
| 409 | 409 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'intersects'); |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - /** |
|
| 413 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 414 | - * @param $geometryColumn |
|
| 415 | - * @param $geometry |
|
| 416 | - * |
|
| 417 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 418 | - */ |
|
| 419 | - public function scopeOverlaps($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 420 | - { |
|
| 412 | + /** |
|
| 413 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 414 | + * @param $geometryColumn |
|
| 415 | + * @param $geometry |
|
| 416 | + * |
|
| 417 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 418 | + */ |
|
| 419 | + public function scopeOverlaps($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 420 | + { |
|
| 421 | 421 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'overlaps'); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - /** |
|
| 425 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 426 | - * @param $geometryColumn |
|
| 427 | - * @param $geometry |
|
| 428 | - * |
|
| 429 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 430 | - */ |
|
| 431 | - public function scopeDoesTouch($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 432 | - { |
|
| 424 | + /** |
|
| 425 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 426 | + * @param $geometryColumn |
|
| 427 | + * @param $geometry |
|
| 428 | + * |
|
| 429 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 430 | + */ |
|
| 431 | + public function scopeDoesTouch($query, $geometryColumn, $geometry): EloquentBuilder |
|
| 432 | + { |
|
| 433 | 433 | return $this->scopeComparison($query, $geometryColumn, $geometry, 'touches'); |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -14,21 +14,21 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Builder extends EloquentBuilder |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @inheritDoc |
|
| 19 | - */ |
|
| 17 | + /** |
|
| 18 | + * @inheritDoc |
|
| 19 | + */ |
|
| 20 | 20 | public function update(array $values) |
| 21 | 21 | { |
| 22 | 22 | foreach ($values as $key => &$value) { |
| 23 | 23 | if ($value instanceof Geometry) { |
| 24 | - try { |
|
| 25 | - $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), FALSE), 'json') |
|
| 26 | - ->out('wkt'); |
|
| 27 | - } catch (\Exception $e) { |
|
| 28 | - throw new SpatialParseException(\sprintf('Unable to parse geometry data for column %s.',$key), 0, $e); |
|
| 29 | - } |
|
| 24 | + try { |
|
| 25 | + $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), FALSE), 'json') |
|
| 26 | + ->out('wkt'); |
|
| 27 | + } catch (\Exception $e) { |
|
| 28 | + throw new SpatialParseException(\sprintf('Unable to parse geometry data for column %s.',$key), 0, $e); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $value = $this->getQuery()->raw("ST_GeomFromText('{$wkt}')"); |
|
| 31 | + $value = $this->getQuery()->raw("ST_GeomFromText('{$wkt}')"); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), FALSE), 'json') |
| 26 | 26 | ->out('wkt'); |
| 27 | 27 | } catch (\Exception $e) { |
| 28 | - throw new SpatialParseException(\sprintf('Unable to parse geometry data for column %s.',$key), 0, $e); |
|
| 28 | + throw new SpatialParseException(\sprintf('Unable to parse geometry data for column %s.', $key), 0, $e); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | $value = $this->getQuery()->raw("ST_GeomFromText('{$wkt}')"); |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | foreach ($values as $key => &$value) { |
| 23 | 23 | if ($value instanceof Geometry) { |
| 24 | 24 | try { |
| 25 | - $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), FALSE), 'json') |
|
| 25 | + $wkt = geoPHP::load(json_decode(json_encode($value->jsonSerialize()), false), 'json') |
|
| 26 | 26 | ->out('wkt'); |
| 27 | 27 | } catch (\Exception $e) { |
| 28 | 28 | throw new SpatialParseException(\sprintf('Unable to parse geometry data for column %s.',$key), 0, $e); |
@@ -13,53 +13,53 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | class PostgresGrammar extends BasePostgresGrammar |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @inheritDoc |
|
| 18 | - */ |
|
| 19 | - public function typePoint(Fluent $column) |
|
| 20 | - { |
|
| 21 | - return parent::typePoint($column); |
|
| 22 | - } |
|
| 16 | + /** |
|
| 17 | + * @inheritDoc |
|
| 18 | + */ |
|
| 19 | + public function typePoint(Fluent $column) |
|
| 20 | + { |
|
| 21 | + return parent::typePoint($column); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @inheritDoc |
|
| 26 | - */ |
|
| 27 | - public function typeMultiPoint(Fluent $column) |
|
| 28 | - { |
|
| 29 | - return parent::typeMultiPoint($column); |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * @inheritDoc |
|
| 26 | + */ |
|
| 27 | + public function typeMultiPoint(Fluent $column) |
|
| 28 | + { |
|
| 29 | + return parent::typeMultiPoint($column); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @inheritDoc |
|
| 34 | - */ |
|
| 35 | - public function typePolygon(Fluent $column) |
|
| 36 | - { |
|
| 37 | - return parent::typePolygon($column); |
|
| 38 | - } |
|
| 32 | + /** |
|
| 33 | + * @inheritDoc |
|
| 34 | + */ |
|
| 35 | + public function typePolygon(Fluent $column) |
|
| 36 | + { |
|
| 37 | + return parent::typePolygon($column); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @inheritDoc |
|
| 42 | - */ |
|
| 43 | - public function typeMultiPolygon(Fluent $column) |
|
| 44 | - { |
|
| 45 | - return parent::typeMultiPolygon($column); |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * @inheritDoc |
|
| 42 | + */ |
|
| 43 | + public function typeMultiPolygon(Fluent $column) |
|
| 44 | + { |
|
| 45 | + return parent::typeMultiPolygon($column); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @inheritDoc |
|
| 50 | - */ |
|
| 51 | - public function typeLineString(Fluent $column) |
|
| 52 | - { |
|
| 53 | - return parent::typeLineString($column); |
|
| 54 | - } |
|
| 48 | + /** |
|
| 49 | + * @inheritDoc |
|
| 50 | + */ |
|
| 51 | + public function typeLineString(Fluent $column) |
|
| 52 | + { |
|
| 53 | + return parent::typeLineString($column); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @inheritDoc |
|
| 58 | - */ |
|
| 59 | - public function typeMultiLineString(Fluent $column) |
|
| 60 | - { |
|
| 61 | - return parent::typeMultiLineString($column); |
|
| 62 | - } |
|
| 56 | + /** |
|
| 57 | + * @inheritDoc |
|
| 58 | + */ |
|
| 59 | + public function typeMultiLineString(Fluent $column) |
|
| 60 | + { |
|
| 61 | + return parent::typeMultiLineString($column); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * @inheritDoc |
@@ -69,21 +69,21 @@ discard block |
||
| 69 | 69 | return 'GEOGRAPHY'; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @inheritDoc |
|
| 74 | - */ |
|
| 75 | - public function typeGeometry(Fluent $column) |
|
| 76 | - { |
|
| 77 | - return parent::typeGeometry( $column); |
|
| 78 | - } |
|
| 72 | + /** |
|
| 73 | + * @inheritDoc |
|
| 74 | + */ |
|
| 75 | + public function typeGeometry(Fluent $column) |
|
| 76 | + { |
|
| 77 | + return parent::typeGeometry( $column); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @inheritDoc |
|
| 82 | - */ |
|
| 83 | - public function typeGeometryCollection(Fluent $column) |
|
| 84 | - { |
|
| 85 | - return parent::typeGeometryCollection($column); |
|
| 86 | - } |
|
| 80 | + /** |
|
| 81 | + * @inheritDoc |
|
| 82 | + */ |
|
| 83 | + public function typeGeometryCollection(Fluent $column) |
|
| 84 | + { |
|
| 85 | + return parent::typeGeometryCollection($column); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * Adds a statement to create the postgis extension |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | */ |
| 75 | 75 | public function typeGeometry(Fluent $column) |
| 76 | 76 | { |
| 77 | - return parent::typeGeometry( $column); |
|
| 77 | + return parent::typeGeometry($column); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -12,22 +12,22 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GrammarFactory { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param string $name |
|
| 17 | - * |
|
| 18 | - * @return \Illuminate\Database\Schema\Grammars\Grammar |
|
| 19 | - */ |
|
| 20 | - public static function make(string $name): Grammar { |
|
| 21 | - switch($name){ |
|
| 22 | - case 'mysql': |
|
| 23 | - return new MySqlGrammar(); |
|
| 24 | - break; |
|
| 25 | - case 'postgresql': |
|
| 26 | - case 'pg_sql': |
|
| 27 | - return new PostgresGrammar(); |
|
| 28 | - break; |
|
| 29 | - } |
|
| 15 | + /** |
|
| 16 | + * @param string $name |
|
| 17 | + * |
|
| 18 | + * @return \Illuminate\Database\Schema\Grammars\Grammar |
|
| 19 | + */ |
|
| 20 | + public static function make(string $name): Grammar { |
|
| 21 | + switch($name){ |
|
| 22 | + case 'mysql': |
|
| 23 | + return new MySqlGrammar(); |
|
| 24 | + break; |
|
| 25 | + case 'postgresql': |
|
| 26 | + case 'pg_sql': |
|
| 27 | + return new PostgresGrammar(); |
|
| 28 | + break; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - throw new \InvalidArgumentException(\sprintf('%s is not a supported grammar.', $name)); |
|
| 32 | - } |
|
| 31 | + throw new \InvalidArgumentException(\sprintf('%s is not a supported grammar.', $name)); |
|
| 32 | + } |
|
| 33 | 33 | } |
| 34 | 34 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | * @return \Illuminate\Database\Schema\Grammars\Grammar |
| 19 | 19 | */ |
| 20 | 20 | public static function make(string $name): Grammar { |
| 21 | - switch($name){ |
|
| 21 | + switch ($name) { |
|
| 22 | 22 | case 'mysql': |
| 23 | 23 | return new MySqlGrammar(); |
| 24 | 24 | break; |
@@ -10,7 +10,8 @@ discard block |
||
| 10 | 10 | * @package LaravelSpatial\Schema\Grammars |
| 11 | 11 | * @internal |
| 12 | 12 | */ |
| 13 | -class GrammarFactory { |
|
| 13 | +class GrammarFactory |
|
| 14 | +{ |
|
| 14 | 15 | |
| 15 | 16 | /** |
| 16 | 17 | * @param string $name |
@@ -18,7 +19,7 @@ discard block |
||
| 18 | 19 | * @return \Illuminate\Database\Schema\Grammars\Grammar |
| 19 | 20 | */ |
| 20 | 21 | public static function make(string $name): Grammar { |
| 21 | - switch($name){ |
|
| 22 | + switch($name) { |
|
| 22 | 23 | case 'mysql': |
| 23 | 24 | return new MySqlGrammar(); |
| 24 | 25 | break; |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class PostgresBuilder extends BasePostgresBuilder { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @inheritDoc |
|
| 17 | - */ |
|
| 18 | - protected function createBlueprint($table, Closure $callback = null) |
|
| 19 | - { |
|
| 20 | - return new Blueprint($table, $callback); |
|
| 21 | - } |
|
| 15 | + /** |
|
| 16 | + * @inheritDoc |
|
| 17 | + */ |
|
| 18 | + protected function createBlueprint($table, Closure $callback = null) |
|
| 19 | + { |
|
| 20 | + return new Blueprint($table, $callback); |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -10,7 +10,8 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * @package LaravelSpatial\Schema |
| 12 | 12 | */ |
| 13 | -class PostgresBuilder extends BasePostgresBuilder { |
|
| 13 | +class PostgresBuilder extends BasePostgresBuilder |
|
| 14 | +{ |
|
| 14 | 15 | |
| 15 | 16 | /** |
| 16 | 17 | * @inheritDoc |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class PostgresConnection extends \Illuminate\Database\PostgresConnection |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @inheritDoc |
|
| 15 | - * @throws \Doctrine\DBAL\DBALException |
|
| 16 | - */ |
|
| 13 | + /** |
|
| 14 | + * @inheritDoc |
|
| 15 | + * @throws \Doctrine\DBAL\DBALException |
|
| 16 | + */ |
|
| 17 | 17 | public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) |
| 18 | 18 | { |
| 19 | 19 | parent::__construct($pdo, $database, $tablePrefix, $config); |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | $this->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'string'); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @inheritDoc |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @inheritDoc |
|
| 27 | + */ |
|
| 28 | 28 | public function getSchemaBuilder() |
| 29 | 29 | { |
| 30 | 30 | if ($this->schemaGrammar === NULL) { |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function getSchemaBuilder() |
| 29 | 29 | { |
| 30 | - if ($this->schemaGrammar === NULL) { |
|
| 30 | + if ($this->schemaGrammar === null) { |
|
| 31 | 31 | $this->useDefaultSchemaGrammar(); |
| 32 | 32 | } |
| 33 | 33 | |
@@ -16,17 +16,17 @@ |
||
| 16 | 16 | { |
| 17 | 17 | const POINT = 'point'; |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @inheritDoc |
|
| 21 | - */ |
|
| 19 | + /** |
|
| 20 | + * @inheritDoc |
|
| 21 | + */ |
|
| 22 | 22 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
| 23 | 23 | { |
| 24 | - return GrammarFactory::make($platform->getName())->typePoint(new Fluent); |
|
| 24 | + return GrammarFactory::make($platform->getName())->typePoint(new Fluent); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @inheritDoc |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @inheritDoc |
|
| 29 | + */ |
|
| 30 | 30 | public function getName() |
| 31 | 31 | { |
| 32 | 32 | return self::POINT; |
@@ -16,17 +16,17 @@ |
||
| 16 | 16 | { |
| 17 | 17 | const MULTIPOLYGON = 'multipolygon'; |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @inheritDoc |
|
| 21 | - */ |
|
| 19 | + /** |
|
| 20 | + * @inheritDoc |
|
| 21 | + */ |
|
| 22 | 22 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
| 23 | 23 | { |
| 24 | - return GrammarFactory::make($platform->getName())->typeMultipolygon(new Fluent()); |
|
| 24 | + return GrammarFactory::make($platform->getName())->typeMultipolygon(new Fluent()); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @inheritDoc |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @inheritDoc |
|
| 29 | + */ |
|
| 30 | 30 | public function getName() |
| 31 | 31 | { |
| 32 | 32 | return self::MULTIPOLYGON; |