Commit 33d21034 authored by Kris Vanneste's avatar Kris Vanneste
Browse files

Allowed 'selection_dict' property of GisData to be a string (attribute filter...

Allowed 'selection_dict' property of GisData to be a string (attribute filter passed to read_gis_file function), and modified get_data method accordingly.

git-svn-id: https://svn.seismo.oma.be/svn/seismo/mapping/layeredbasemap/trunk@7644 40b490c5-b4d9-47cb-8714-9bef99b524d5
parent c46fb80b
......@@ -47,6 +47,9 @@ class GisData(BasemapData):
dict, mapping column names to values; only matching records will be selected
Note: multiple values mapped to a column name will act as logical OR,
multiple keys will act as logical AND operator.
Alternatively: str, attribute_filter that will be directly passed to
:func:`read_gis_file`
(default: None)
:param joined_attributes:
dict, mapping additional attribute names (not present in the GIS table)
to dictionaries containing two entries:
......@@ -57,7 +60,7 @@ class GisData(BasemapData):
(default: True)
:param invert_selection:
bool, whether or not to invert the selection criteria in
:param:`selection_dict`
:param:`selection_dict`. Ignored if :param:`selection_dict` is a string
(default: False)
:param region:
(west, east, south, north) tuple in geographic coordinates,
......@@ -170,7 +173,7 @@ class GisData(BasemapData):
for colname in polygon_value_colnames:
polygon_data.values[colname] = []
if not self.invert_selection:
if not self.invert_selection or isinstance(self.selection_dict, basestring):
## Delegate selection to read_gis_file
attribute_filter = self.selection_dict
else:
......@@ -179,16 +182,19 @@ class GisData(BasemapData):
attribute_filter=attribute_filter,
region=self.region, out_srs=out_srs,
verbose=self.verbose):
selected = np.zeros(len(self.selection_dict.keys()))
for i, (selection_colname, selection_value) in enumerate(self.selection_dict.items()):
if rec[selection_colname] == selection_value:
selected[i] = 1
elif hasattr(selection_value, '__iter__') and rec[selection_colname] in selection_value:
selected[i] = 1
else:
selected[i] = 0
if self.invert_selection:
selected = np.abs(selected - 1)
if isinstance(self.selection_dict, dict):
selected = np.zeros(len(self.selection_dict.keys()))
for i, (selection_colname, selection_value) in enumerate(self.selection_dict.items()):
if rec[selection_colname] == selection_value:
selected[i] = 1
elif hasattr(selection_value, '__iter__') and rec[selection_colname] in selection_value:
selected[i] = 1
else:
selected[i] = 0
if self.invert_selection:
selected = np.abs(selected - 1)
else:
selected = np.array([True])
if selected.all():
label = rec.get(self.label_colname)
if label is None and self.label_colname in self.joined_attributes:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment