mirror of https://github.com/apache/superset.git
[bugfix] geohash lat/long is reversed (#5695)
* [bugfix] geohash lat/long is reversed This allows support for reversing geohashes. Note that the default option was the wrong way. * addressing comments * make reverse_geohash_decode a staticmethod
This commit is contained in:
parent
2a8cd43881
commit
b42f8a23b1
|
@ -51,6 +51,7 @@ export default class SpatialControl extends React.Component {
|
||||||
};
|
};
|
||||||
this.toggleCheckbox = this.toggleCheckbox.bind(this);
|
this.toggleCheckbox = this.toggleCheckbox.bind(this);
|
||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
|
this.renderReverseCheckbox = this.renderReverseCheckbox.bind(this);
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.onChange();
|
this.onChange();
|
||||||
|
@ -75,6 +76,7 @@ export default class SpatialControl extends React.Component {
|
||||||
}
|
}
|
||||||
} else if (type === spatialTypes.geohash) {
|
} else if (type === spatialTypes.geohash) {
|
||||||
value.geohashCol = this.state.geohashCol;
|
value.geohashCol = this.state.geohashCol;
|
||||||
|
value.reverseCheckbox = this.state.reverseCheckbox;
|
||||||
if (!value.geohashCol) {
|
if (!value.geohashCol) {
|
||||||
errors.push(errMsg);
|
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() {
|
renderPopover() {
|
||||||
return (
|
return (
|
||||||
<Popover id="filter-popover">
|
<Popover id="filter-popover">
|
||||||
|
@ -150,12 +159,11 @@ export default class SpatialControl extends React.Component {
|
||||||
>
|
>
|
||||||
<Row>
|
<Row>
|
||||||
<Col md={6}>
|
<Col md={6}>
|
||||||
Column
|
{t('Column')}
|
||||||
{this.renderSelect('lonlatCol', spatialTypes.delimited)}
|
{this.renderSelect('lonlatCol', spatialTypes.delimited)}
|
||||||
</Col>
|
</Col>
|
||||||
<Col md={6}>
|
<Col md={6}>
|
||||||
{t('Reverse lat/long ')}
|
{this.renderReverseCheckbox()}
|
||||||
<Checkbox checked={this.state.reverseCheckbox} onChange={this.toggleCheckbox} />
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</PopoverSection>
|
</PopoverSection>
|
||||||
|
@ -169,6 +177,9 @@ export default class SpatialControl extends React.Component {
|
||||||
Column
|
Column
|
||||||
{this.renderSelect('geohashCol', spatialTypes.geohash)}
|
{this.renderSelect('geohashCol', spatialTypes.geohash)}
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col md={6}>
|
||||||
|
{this.renderReverseCheckbox()}
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</PopoverSection>
|
</PopoverSection>
|
||||||
<div className="clearfix">
|
<div className="clearfix">
|
||||||
|
|
|
@ -2101,10 +2101,24 @@ class BaseDeckGLViz(BaseViz):
|
||||||
_('Invalid spatial point encountered: %s' % s))
|
_('Invalid spatial point encountered: %s' % s))
|
||||||
return (p.latitude, p.longitude)
|
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):
|
def process_spatial_data_obj(self, key, df):
|
||||||
spatial = self.form_data.get(key)
|
spatial = self.form_data.get(key)
|
||||||
if spatial is None:
|
if spatial is None:
|
||||||
raise ValueError(_('Bad spatial key'))
|
raise ValueError(_('Bad spatial key'))
|
||||||
|
|
||||||
if spatial.get('type') == 'latlong':
|
if spatial.get('type') == 'latlong':
|
||||||
df[key] = list(zip(
|
df[key] = list(zip(
|
||||||
pd.to_numeric(df[spatial.get('lonCol')], errors='coerce'),
|
pd.to_numeric(df[spatial.get('lonCol')], errors='coerce'),
|
||||||
|
@ -2113,19 +2127,14 @@ class BaseDeckGLViz(BaseViz):
|
||||||
elif spatial.get('type') == 'delimited':
|
elif spatial.get('type') == 'delimited':
|
||||||
lon_lat_col = spatial.get('lonlatCol')
|
lon_lat_col = spatial.get('lonlatCol')
|
||||||
df[key] = df[lon_lat_col].apply(self.parse_coordinates)
|
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]
|
del df[lon_lat_col]
|
||||||
elif spatial.get('type') == 'geohash':
|
elif spatial.get('type') == 'geohash':
|
||||||
latlong = df[spatial.get('geohashCol')].map(geohash.decode)
|
df[key] = df[spatial.get('geohashCol')].map(self.reverse_geohash_decode)
|
||||||
df[key] = list(zip(latlong.apply(lambda x: x[0]),
|
|
||||||
latlong.apply(lambda x: x[1])))
|
|
||||||
del df[spatial.get('geohashCol')]
|
del df[spatial.get('geohashCol')]
|
||||||
|
|
||||||
|
if spatial.get('reverseCheckbox'):
|
||||||
|
self.reverse_latlong(df, key)
|
||||||
|
|
||||||
if df.get(key) is None:
|
if df.get(key) is None:
|
||||||
raise NullValueException(_('Encountered invalid NULL spatial entry, \
|
raise NullValueException(_('Encountered invalid NULL spatial entry, \
|
||||||
please consider filtering those out'))
|
please consider filtering those out'))
|
||||||
|
|
Loading…
Reference in New Issue