-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #483 from jjrom/develop
Replace SQL function ST_SplitDateLine from tamn with PHP antimeridian code
- Loading branch information
Showing
42 changed files
with
6,137 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/command/with-contenv php | ||
|
||
<?php | ||
|
||
require_once("/app/resto/core/RestoConstants.php"); | ||
require_once("/app/resto/core/RestoDatabaseDriver.php"); | ||
require_once("/app/resto/core/utils/RestoLogUtil.php"); | ||
require_once("/app/resto/core/utils/Antimeridian.php"); | ||
require_once("/app/resto/core/dbfunctions/UsersFunctions.php"); | ||
|
||
/* | ||
* Read configuration from file... | ||
*/ | ||
$configFile = '/etc/resto/config.php'; | ||
if ( !file_exists($configFile)) { | ||
exit(1); | ||
} | ||
$config = include($configFile); | ||
$dbDriver = new RestoDatabaseDriver($config['database'] ?? null); | ||
$queries = []; | ||
|
||
$antimeridian = new AntiMeridian(); | ||
|
||
$targetSchema = $dbDriver->targetSchema; | ||
|
||
try { | ||
|
||
$dbDriver->query('BEGIN'); | ||
|
||
// First populate geometry column | ||
$dbDriver->query('UPDATE ' . $targetSchema . '.feature SET geometry = geom WHERE geometry IS NULL'); | ||
|
||
// Now convert all geometry so there are correctly computed with antimeridian | ||
$results = $dbDriver->query('SELECT id, ST_AsGeoJSON(geometry) as geometry FROM ' . $targetSchema . '.feature'); | ||
while ($result = pg_fetch_assoc($results)) { | ||
$dbDriver->pQuery('UPDATE ' . $targetSchema . '.feature SET geom=ST_SetSRID(ST_GeomFromGeoJSON($2), 4326) WHERE id=$1', array( | ||
$result['id'], | ||
json_encode($antimeridian->fixGeoJSON(json_decode($result['geometry'], true)), JSON_UNESCAPED_SLASHES) | ||
)); | ||
} | ||
|
||
$dbDriver->query('COMMIT'); | ||
|
||
} catch(Exception $e){ | ||
$dbDriver->query('ROLLBACK'); | ||
RestoLogUtil::httpError(500, $e->getMessage()); | ||
} | ||
echo "Looks good\n"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.