MAPG-111 store map area in table 'maps'

This commit is contained in:
Bence Pőcze 2020-06-12 21:54:05 +02:00
parent 9ca97dccb9
commit 4d7c86fd1b
2 changed files with 28 additions and 0 deletions

View 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();

View File

@ -0,0 +1,4 @@
ALTER TABLE
`maps`
ADD
`area` decimal(13, 4) NOT NULL DEFAULT 0.0;