jenkins-bot has submitted this change and it was merged.
Change subject: Store coordinates as decimal
......................................................................
Store coordinates as decimal
Otherwise, MySQL performs an arbitrary rounding when returning results.
The precision is chosen as following:
* 3 digits before the point [-360; 360]
* 8 digits after. GeoData compares coordinates with 1e-6 precision, 2 extra
digits
to reduce the possibility of "smart" rounding.
Bug: T78715
Change-Id: I4762ce04d9c2c6554bc3bfb3994c9ef242a51d8c
---
M GeoDataHooks.php
M GeoDataMath.php
M sql/db-backed.sql
M sql/externally-backed.sql
A sql/float-to-decimal.sql
5 files changed, 24 insertions(+), 5 deletions(-)
Approvals:
Springle: Looks good to me, but someone else must approve
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/GeoDataHooks.php b/GeoDataHooks.php
index 291b5ec..3bece9d 100644
--- a/GeoDataHooks.php
+++ b/GeoDataHooks.php
@@ -24,6 +24,7 @@
} else {
$updater->addExtensionTable(
'geo_tags', dirname( __FILE__ ) . '/sql/db-backed.sql' );
}
+ $updater->addExtensionUpdate( array(
'GeoDataHooks::upgradeToDecimal' ) );
break;
default:
throw new MWException( 'GeoData extension
currently supports only MySQL and SQLite' );
@@ -31,6 +32,22 @@
return true;
}
+ public static function upgradeToDecimal( DatabaseUpdater $updater ) {
+ $db = $updater->getDB();
+ if ( $db->getType() != 'mysql' ) {
+ // FLOAT is the same thing as DOUBLE in SQLite
+ return;
+ }
+ $field = $db->fieldInfo( 'geo_tags', 'gt_lat' );
+ // Doesn't support the old API, oh well
+ if ( $field->type() === MYSQLI_TYPE_FLOAT ) {
+ $updater->output( "...upgrading geo_tags coordinates
from FLOAT to DECIMAL.\n" );
+ $db->sourceFile( __DIR__ . '/sql/float-to-decimal.sql'
);
+ } else {
+ $updater->output( "...coordinates are already DECIMAL
in geo_tags.\n" );
+ }
+ }
+
/**
* UnitTestsList hook handler
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
diff --git a/GeoDataMath.php b/GeoDataMath.php
index fe97ed8..caf65d2 100644
--- a/GeoDataMath.php
+++ b/GeoDataMath.php
@@ -7,7 +7,7 @@
*
* All the functions that accept coordinates assume that they're in degrees,
not radians.
*/
-/* static */class GeoDataMath {
+class GeoDataMath {
const EARTH_RADIUS = 6371010;
/**
diff --git a/sql/db-backed.sql b/sql/db-backed.sql
index c720331..614901a 100644
--- a/sql/db-backed.sql
+++ b/sql/db-backed.sql
@@ -16,9 +16,9 @@
-- Longitude in fractional parts of degree (by default 1/10th)
gt_lon_int smallint NOT NULL,
-- Latitude of the point in degrees
- gt_lat float NOT NULL,
+ gt_lat decimal(11,8) NOT NULL,
-- Longitude of the point in degrees
- gt_lon float NOT NULL,
+ gt_lon decimal(11,8) NOT NULL,
-- Approximate viewing radius in meters, gives an idea how large the
object is
gt_dim int NULL,
-- Type of the point
diff --git a/sql/externally-backed.sql b/sql/externally-backed.sql
index 2993a65..2a3de3f 100644
--- a/sql/externally-backed.sql
+++ b/sql/externally-backed.sql
@@ -12,9 +12,9 @@
-- or secondary (just mentioned in text)
gt_primary bool NOT NULL,
-- Latitude of the point in degrees
- gt_lat float NOT NULL,
+ gt_lat decimal(11,8) NOT NULL,
-- Longitude of the point in degrees
- gt_lon float NOT NULL,
+ gt_lon decimal(11,8) NOT NULL,
-- Approximate viewing radius in meters, gives an idea how large the
object is
gt_dim int NULL,
-- Type of the point
diff --git a/sql/float-to-decimal.sql b/sql/float-to-decimal.sql
new file mode 100644
index 0000000..ae46711
--- /dev/null
+++ b/sql/float-to-decimal.sql
@@ -0,0 +1,2 @@
+ALTER TABLE /*_*/geo_tags MODIFY gt_lat decimal(11,8),
+ MODIFY gt_lon decimal(11,8);
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/180704
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4762ce04d9c2c6554bc3bfb3994c9ef242a51d8c
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: Springle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits