-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessing.py
39 lines (32 loc) · 1.24 KB
/
processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from django.conf import settings
#
# Utility methods for transforming shapefile columns into useful representations
# supplementing the functions that come with the boundary service.
#
class simple_index_namer():
"""
Name features with a joined combination of attributes, optionally passing
the result through a normalizing function. Adds an additonal suffix if
multiple values are used.
"""
def __init__(self, attribute_names, seperator='-', normalizer=None):
self.attribute_names = attribute_names
self.seperator = seperator
self.normalizer = normalizer
self.found = {}
def __call__(self, feature):
attribute_values = map(str, map(feature.get, self.attribute_names))
name = self.seperator.join(attribute_values).strip()
if self.normalizer:
normed = self.normalizer(name)
if not normed:
raise ValueError('Failed to normalize \"%s\".' % name)
else:
name = normed
# Check if found already
if name in self.found:
self.found[name] = self.found[name] + 1
name = name + self.seperator + str(self.found[name])
else:
self.found[name] = 0
return name