You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/22 05:58:48 UTC

[GitHub] mistercrunch closed pull request #5695: [bugfix] geohash lat/long is reversed

mistercrunch closed pull request #5695: [bugfix] geohash lat/long is reversed
URL: https://github.com/apache/incubator-superset/pull/5695
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/explore/components/controls/SpatialControl.jsx b/superset/assets/src/explore/components/controls/SpatialControl.jsx
index d9db801c4b..97e6b0c3e4 100644
--- a/superset/assets/src/explore/components/controls/SpatialControl.jsx
+++ b/superset/assets/src/explore/components/controls/SpatialControl.jsx
@@ -51,6 +51,7 @@ export default class SpatialControl extends React.Component {
     };
     this.toggleCheckbox = this.toggleCheckbox.bind(this);
     this.onChange = this.onChange.bind(this);
+    this.renderReverseCheckbox = this.renderReverseCheckbox.bind(this);
   }
   componentDidMount() {
     this.onChange();
@@ -75,6 +76,7 @@ export default class SpatialControl extends React.Component {
       }
     } else if (type === spatialTypes.geohash) {
       value.geohashCol = this.state.geohashCol;
+      value.reverseCheckbox = this.state.reverseCheckbox;
       if (!value.geohashCol) {
         errors.push(errMsg);
       }
@@ -120,6 +122,13 @@ export default class SpatialControl extends React.Component {
       />
     );
   }
+  renderReverseCheckbox() {
+    return (
+      <span>
+        {t('Reverse lat/long ')}
+        <Checkbox checked={this.state.reverseCheckbox} onChange={this.toggleCheckbox} />
+      </span>);
+  }
   renderPopover() {
     return (
       <Popover id="filter-popover">
@@ -150,12 +159,11 @@ export default class SpatialControl extends React.Component {
           >
             <Row>
               <Col md={6}>
-                Column
+                {t('Column')}
                 {this.renderSelect('lonlatCol', spatialTypes.delimited)}
               </Col>
               <Col md={6}>
-                {t('Reverse lat/long ')}
-                <Checkbox checked={this.state.reverseCheckbox} onChange={this.toggleCheckbox} />
+                {this.renderReverseCheckbox()}
               </Col>
             </Row>
           </PopoverSection>
@@ -169,6 +177,9 @@ export default class SpatialControl extends React.Component {
                 Column
                 {this.renderSelect('geohashCol', spatialTypes.geohash)}
               </Col>
+              <Col md={6}>
+                {this.renderReverseCheckbox()}
+              </Col>
             </Row>
           </PopoverSection>
           <div className="clearfix">
diff --git a/superset/viz.py b/superset/viz.py
index 9113b038d0..82992223e1 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -2101,10 +2101,24 @@ def parse_coordinates(s):
                 _('Invalid spatial point encountered: %s' % s))
         return (p.latitude, p.longitude)
 
+    @staticmethod
+    def reverse_geohash_decode(geohash_code):
+        lat, lng = geohash.decode(geohash_code)
+        return (lng, lat)
+
+    @staticmethod
+    def reverse_latlong(df, key):
+        df[key] = [
+            tuple(reversed(o))
+            for o in df[key]
+            if isinstance(o, (list, tuple))
+        ]
+
     def process_spatial_data_obj(self, key, df):
         spatial = self.form_data.get(key)
         if spatial is None:
             raise ValueError(_('Bad spatial key'))
+
         if spatial.get('type') == 'latlong':
             df[key] = list(zip(
                 pd.to_numeric(df[spatial.get('lonCol')], errors='coerce'),
@@ -2113,19 +2127,14 @@ def process_spatial_data_obj(self, key, df):
         elif spatial.get('type') == 'delimited':
             lon_lat_col = spatial.get('lonlatCol')
             df[key] = df[lon_lat_col].apply(self.parse_coordinates)
-
-            if spatial.get('reverseCheckbox'):
-                df[key] = [
-                    tuple(reversed(o)) if isinstance(o, (list, tuple)) else (0, 0)
-                    for o in df[key]
-                ]
             del df[lon_lat_col]
         elif spatial.get('type') == 'geohash':
-            latlong = df[spatial.get('geohashCol')].map(geohash.decode)
-            df[key] = list(zip(latlong.apply(lambda x: x[0]),
-                               latlong.apply(lambda x: x[1])))
+            df[key] = df[spatial.get('geohashCol')].map(self.reverse_geohash_decode)
             del df[spatial.get('geohashCol')]
 
+        if spatial.get('reverseCheckbox'):
+            self.reverse_latlong(df, key)
+
         if df.get(key) is None:
             raise NullValueException(_('Encountered invalid NULL spatial entry, \
                                        please consider filtering those out'))


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org