# Path: geotweet/mapreduce/utils/proj.py
# def project(lonlat):
#     return transform(proj4326, proj102005, *lonlat)
# 
# def rproject(lonlat):
#     return transform(proj102005, proj4326, *lonlat)


import sys
import os
import hashlib
import json
import Geohash
import shapely
from shapely.geometry import shape
from shapely.geometry.point import Point
from rtree import index
from reader import FileReader
from .proj import project, rproject
        feature = self._build_obj(feature)
        self.data_store[key] = feature
        self.idx.insert(key, feature['geometry'].bounds)


class CachedLookup(SpatialLookup):
    """ Cache results of spatial lookups """

    geohash_cache = {}

    def __init__(self, precision=7,  *args, **kwargs):
        super(CachedLookup, self).__init__(*args, **kwargs)
        self.precision = precision
        self.hit = 0
        self.miss = 0

    def get(self, point, buffer_size=0, multiple=False):
        """ lookup state and county based on geohash of coordinates from tweet """
        lon, lat = point
        geohash = Geohash.encode(lat, lon, precision=self.precision)
        key = (geohash, buffer_size, multiple)
        if key in self.geohash_cache:
            # cache hit on geohash
            self.hit += 1
            #print self.hit, self.miss
            return self.geohash_cache[key]
        self.miss += 1
        # cache miss on geohash
        # project point to ESRI:102005
        lat, lon = Geohash.decode(geohash)

# Path: geotweet/mapreduce/utils/proj.py
# def project(lonlat):
#     return transform(proj4326, proj102005, *lonlat)
# 
# def rproject(lonlat):
#     return transform(proj102005, proj4326, *lonlat)


# Path: geotweet/mapreduce/utils/lookup.py
import sys
import os
import hashlib
import json
import Geohash
import shapely
from shapely.geometry import shape
from shapely.geometry.point import Point
from rtree import index
from reader import FileReader
from .proj import project, rproject

        feature = self._build_obj(feature)
        self.data_store[key] = feature
        self.idx.insert(key, feature['geometry'].bounds)


class CachedLookup(SpatialLookup):
    """ Cache results of spatial lookups """

    geohash_cache = {}

    def __init__(self, precision=7,  *args, **kwargs):
        super(CachedLookup, self).__init__(*args, **kwargs)
        self.precision = precision
        self.hit = 0
        self.miss = 0

    def get(self, point, buffer_size=0, multiple=False):
        """ lookup state and county based on geohash of coordinates from tweet """
        lon, lat = point
        geohash = Geohash.encode(lat, lon, precision=self.precision)
        key = (geohash, buffer_size, multiple)
        if key in self.geohash_cache:
            # cache hit on geohash
            self.hit += 1
            #print self.hit, self.miss
            return self.geohash_cache[key]
        self.miss += 1
        # cache miss on geohash
        # project point to ESRI:102005
        lat, lon = Geohash.decode(geohash)

        proj_point = project([float(lon), float(lat)])