MAPG-111 store map area in table 'maps'
This commit is contained in:
parent
9ca97dccb9
commit
4d7c86fd1b
24
database/migrations/data/20200612_2124_map_area.php
Normal file
24
database/migrations/data/20200612_2124_map_area.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use MapGuesser\Database\Query\Modify;
|
||||
use MapGuesser\Database\Query\Select;
|
||||
use MapGuesser\Interfaces\Database\IResultSet;
|
||||
use MapGuesser\Util\Geo\Bounds;
|
||||
|
||||
$select = new Select(\Container::$dbConnection, 'maps');
|
||||
$select->columns(['id', 'bound_south_lat', 'bound_west_lng', 'bound_north_lat', 'bound_east_lng']);
|
||||
|
||||
$result = $select->execute();
|
||||
|
||||
\Container::$dbConnection->startTransaction();
|
||||
|
||||
while ($map = $result->fetch(IResultSet::FETCH_ASSOC)) {
|
||||
$bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']);
|
||||
|
||||
$modify = new Modify(\Container::$dbConnection, 'maps');
|
||||
$modify->setId($map['id']);
|
||||
$modify->set('area', $bounds->calculateApproximateArea());
|
||||
$modify->save();
|
||||
}
|
||||
|
||||
\Container::$dbConnection->commit();
|
4
database/migrations/structure/20200612_2124_map_area.sql
Normal file
4
database/migrations/structure/20200612_2124_map_area.sql
Normal file
@ -0,0 +1,4 @@
|
||||
ALTER TABLE
|
||||
`maps`
|
||||
ADD
|
||||
`area` decimal(13, 4) NOT NULL DEFAULT 0.0;
|
Loading…
Reference in New Issue
Block a user