Example #1
0
 def get(bbox, date, precision_level):
     assert isinstance(bbox, BoundingBox)
     assert isinstance(date, datetime)
     assert date.tzinfo is None
     with get_cursor() as cursor:
         territories = TerritoryCRUD.get_within_bbox_at_time(cursor, bbox, date, precision_level)
         state_ids = frozenset(t.state_id for t in territories)
         states = StateCRUD.get_many(cursor, state_ids)
         return {
             'states' : states,
             'territories' : territories
         }
Example #2
0
 def get_by_state(state_id, date, pixel_width):
     assert isinstance(state_id, int)
     assert isinstance(date, datetime)
     assert isinstance(pixel_width, float)
     with get_cursor() as cursor:
         bbox = StateCRUD.get_bbox(cursor, state_id, date).enlarge_to_aspect_ratio(16/9)
         precision = precision_from_bbox_and_px_width(bbox, pixel_width)
         territories = TerritoryCRUD.get_within_bbox_at_time(cursor, bbox, date, precision)
         state_ids = frozenset(t.state_id for t in territories)
         states = StateCRUD.get_many(cursor, state_ids)
         return {
             'states' : states,
             'territories' : territories,
             'bounding_box' : bbox,
             'date' : date
         }
Example #3
0
 def get_evolution_by_state(state_id, pixel_width):
     assert isinstance(state_id, int)
     assert isinstance(pixel_width, float)
     with get_cursor() as cursor:
         res = []
         for date in _determine_dates_to_show(cursor, state_id):
             try :
                 bbox = StateCRUD.get_bbox(cursor, state_id, date).enlarge_to_aspect_ratio(16/9)
                 logging.error('setting last bbox')
                 last_bbox = bbox
             except NotFound:
                 bbox = last_bbox 
             precision = precision_from_bbox_and_px_width(bbox, pixel_width)
             territories = TerritoryCRUD.get_within_bbox_at_time(cursor, bbox, date, precision)
             state_ids = frozenset(t.state_id for t in territories)
             states = StateCRUD.get_many(cursor, state_ids)
             res.append({
                 'states' : states,
                 'territories' : territories,
                 'bounding_box' : bbox,
                 'date' : date,
                 'lands': LandCRUD.get_lands(cursor, bbox, precision)
             })
         return res