Skip to content

Commit bdfc399

Browse files
Dynamic _Product._layer_lookup to handle year to year layer id changes
1 parent 8e353d6 commit bdfc399

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

cenpy/products.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,23 @@ def _preprocess_variables(self, columns):
7777
@property
7878
def _layer_lookup(self):
7979
"""
80-
The lookup table relating the layers in the WMS service and the levels
81-
supported by this API product.
80+
Create lookup table to translate cenpy levels ('county', 'block',
81+
'tract') to layer id. Dynamically create to handle year to year id
82+
changes (naming changes will break)
8283
"""
83-
pass
8484

85-
@_layer_lookup.getter
86-
def _layer_lookup(self):
87-
raise NotImplementedError(
88-
"This must be implemented on children " "of this class!"
89-
)
85+
supported_levels = {
86+
'States': 'state',
87+
'Counties': 'county',
88+
'Census Blocks': 'block',
89+
'Census Tracts': 'tract',
90+
}
91+
92+
return {
93+
supported_levels[l._name]: l._id
94+
for l in self._api.mapservice.layers if
95+
l._name in ['Counties', 'Census Tracts', 'Census Blocks']
96+
}
9097

9198
def from_place(
9299
self,
@@ -480,8 +487,6 @@ def check_match(
480487
class Decennial2010(_Product):
481488
"""The 2010 Decennial Census from the Census Bueau"""
482489

483-
_layer_lookup = {"county": 100, "tract": 14, "block": 18}
484-
485490
def __init__(self):
486491
super(Decennial2010, self).__init__()
487492
self._api = APIConnection("DECENNIALSF12010")
@@ -673,8 +678,6 @@ def crosstab_tables(self):
673678
class ACS(_Product):
674679
"""The American Community Survey (5-year vintages) from the Census Bueau"""
675680

676-
_layer_lookup = {"county": 84, "tract": 8}
677-
678681
def __init__(self, year="latest"):
679682
self._cache = dict()
680683
if year == "latest":

0 commit comments

Comments
 (0)