def codeRecord(self, r): if r.source() != 'Milstein Division': return None loc = self._extractLocationStringFromRecord(r) m = None for pattern in self._cross_patterns: m = re.match(pattern, loc) if m: break if not m: return None street1, street2, boro = m.groups() if not boro.startswith('Manhattan'): return None try: avenue, street = parse_street_ave(street1, street2) except ValueError as e: sys.stderr.write('%s: %s\n' % (loc, e.message)) return None # Special cases photo_id = r.photo_id() if photo_id.startswith('723557f'): # These are mislabeled as 93rd and B. avenue, street = 'B', '8' elif photo_id.startswith('711789') or photo_id.startswith('713187'): # Mislabeled as 25th & D. Unclear about the second one. avenue, street = 'A', '25' elif photo_id.startswith('715535f'): # Mislabeled as 103rd & 7th instead of 130th & 7th. # This incorrectly puts it in the middle of Central Park! avenue, street = '7', '130' latlon = coder.code(avenue, street) if not latlon: return None # sys.stderr.write('coded (%s, %s) --> (%s, %s)\n' % (street1, street2, avenue, street)) return { 'address': '@%s,%s' % latlon, 'source': loc, 'grid': '(%s, %s)' % (avenue, street), 'type': 'intersection' }
def test_extrapolate(): assert_close(coder.code('A', '15'), (40.731083, -73.979847)) assert_close(coder.code('A', '20'), (40.734071, -73.977654))
def test_interpolate(): # This is halfway between 26th & 28th. assert_close(coder.code('9', '27'), (40.749020, -73.9995210))
def test_exact(): # It's really Park Avenue South. assert_close(coder.code('4', '17'), (40.736518, -73.988962))