Ejemplo n.º 1
0
 def __init__(self, layer, zoom, x, y, category, metro):
     self.layer = layer
     self.zoom = zoom
     self.x = x
     self.y = y
     self.category = category
     self.metro = metro
     self.color_scheme = color_scheme.cyan_red
     self.decay = 0.0
     self.tile_img = None
     # attempt to get a cached object
     self.tile_dump = self.__get_cached_image()
     if not self.tile_dump:
         half_size = (zoom + 1) * 3 / 2
         self.georange = gmerc.px2ll(x * 256 - half_size,
                                     y * 256 - half_size, zoom)
         self.georange_next = gmerc.px2ll((x + 1) * 256 + half_size,
                                          (y + 1) * 256 + half_size, zoom)
         self.zoom_step = [
             self.georange_next[0] - self.georange[0],
             self.georange_next[1] - self.georange[1]
         ]
         # Get the points and start plotting data
         self.tile_img = self.plot_image(
             provider.get_data(self.zoom, self.layer, self.georange[0],
                               self.georange[1], self.zoom_step[0],
                               self.zoom_step[1], category, metro))
Ejemplo n.º 2
0
    def center2corners(self, center):
        """Gets the lat/lng value of four corners of the image file
        """

        center_px = ll2px(center["lat"], center["lng"], ZOOM_LEVEL)
        west_north_corner = px2ll(center_px[0] - SIZE / 2,
                                  center_px[1] - SIZE / 2, ZOOM_LEVEL)
        east_north_corner = px2ll(center_px[0] + SIZE / 2,
                                  center_px[1] - SIZE / 2, ZOOM_LEVEL)
        west_south_corner = px2ll(center_px[0] - SIZE / 2,
                                  center_px[1] + SIZE / 2, ZOOM_LEVEL)
        east_south_corner = px2ll(center_px[0] + SIZE / 2,
                                  center_px[1] + SIZE / 2, ZOOM_LEVEL)
        return [{
            "lat": west_north_corner[0],
            "lng": west_north_corner[1]
        }, {
            "lat": east_north_corner[0],
            "lng": east_north_corner[1]
        }, {
            "lat": west_south_corner[0],
            "lng": west_south_corner[1]
        }, {
            "lat": east_south_corner[0],
            "lng": east_south_corner[1]
        }]
Ejemplo n.º 3
0
    def __init__(self, zoom, x_tile, y_tile):
        self.zoom = zoom
        self.decay = 0.5
        #dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
        dot_radius = int(math.ceil((self.zoom + 1) * DOT_MULT))

        self.northwest_ll_buffered = gmerc.px2ll(
            (x_tile) * 256 - dot_radius, (y_tile) * 256 - dot_radius, zoom)
        self.northwest_ll = gmerc.px2ll((x_tile) * 256, (y_tile) * 256, zoom)

        self.southeast_ll_buffered = gmerc.px2ll(
            (x_tile + 1) * 256 + dot_radius, (y_tile + 1) * 256 + dot_radius,
            zoom)  #TODO fix this in case we're at the edge of the map!
        self.southeast_ll = gmerc.px2ll((x_tile + 1) * 256, (y_tile + 1) * 256,
                                        zoom)

        # calculate the real values for these without the offsets, otherwise it messes up the __merge_point_in_space calculations
        self.latlng_diff_buffered = [
            self.southeast_ll_buffered[0] - self.northwest_ll_buffered[0],
            self.southeast_ll_buffered[1] - self.northwest_ll_buffered[1]
        ]
        self.latlng_diff = [
            self.southeast_ll[0] - self.northwest_ll[0],
            self.southeast_ll[1] - self.northwest_ll[1]
        ]

        BasicTile.__init__(self, self.northwest_ll_buffered[0],
                           self.northwest_ll_buffered[1],
                           self.latlng_diff_buffered[0],
                           self.latlng_diff_buffered[1])
Ejemplo n.º 4
0
    def __init__(self, color_scheme, dots, zoom, x, y, fspath):
        """x and y are tile coords per Google Maps.
        """

        # Calculate some things.
        # ======================

        dot = dots[zoom]
        self.dots = dots
        self.zoom = zoom

        # Translate tile to pixel coords.
        # -------------------------------

        x1 = x * int(config.get("size"))
        x2 = x1 + 255
        y1 = y * int(config.get("size"))
        y2 = y1 + 255
    
    
        # Expand bounds by one-half dot width.
        # ------------------------------------
    
        x1 = x1 - dot.half_size
        x2 = x2 + dot.half_size
        y1 = y1 - dot.half_size
        y2 = y2 + dot.half_size
        expanded_size = (x2-x1, y2-y1)
    
    
        # Translate new pixel bounds to lat/lng.
        # --------------------------------------
    
        n, w = gmerc.px2ll(x1, y1, zoom)
        s, e = gmerc.px2ll(x2, y2, zoom)


        # Save
        # ====

        self.dot = dot.img
        self.pad = dots[zoom+3].half_size

        self.x = x
        self.y = y

        self.x1 = x1
        self.y1 = y1

        self.x2 = x2
        self.y2 = y2

        self.expanded_size = expanded_size
        self.llbound = (n,s,e,w)
        self.zoom = zoom
        self.fspath = fspath
        self.opacity = OPACITY
        self.color_scheme = color_scheme
Ejemplo n.º 5
0
    def __init__(self, color_scheme, dots, zoom, x, y, fspath):
        """x and y are tile coords per Google Maps.
        """

        # Calculate some things.
        # ======================

        dot = dots[zoom]


        # Translate tile to pixel coords.
        # -------------------------------

        x1 = x * SIZE
        x2 = x1 + 255
        y1 = y * SIZE
        y2 = y1 + 255
    
    
        # Expand bounds by one-half dot width.
        # ------------------------------------
    
        x1 = x1 - dot.half_size
        x2 = x2 + dot.half_size
        y1 = y1 - dot.half_size
        y2 = y2 + dot.half_size
        expanded_size = (x2-x1, y2-y1)
    
    
        # Translate new pixel bounds to lat/lng.
        # --------------------------------------
    
        n, w = gmerc.px2ll(x1, y1, zoom)
        s, e = gmerc.px2ll(x2, y2, zoom)


        # Save
        # ====

        self.dot = dot.img
        self.pad = dot.half_size

        self.x = x
        self.y = y

        self.x1 = x1
        self.y1 = y1

        self.x2 = x2
        self.y2 = y2

        self.expanded_size = expanded_size
        self.llbound = (n,s,e,w)
        self.zoom = zoom
        self.fspath = fspath
        self.opacity = gheat.opacity.zoom_to_opacity[zoom]
        self.color_scheme = color_scheme
Ejemplo n.º 6
0
    def __init__(self, mapname, map_type,  zoom, x, y, fspath):
        """x and y are tile coords per Google Maps.
        """

        # Translate tile to pixel coords.
        # -------------------------------

        x1 = x * SIZE
        x2 = x1 + 255
        y1 = y * SIZE
        y2 = y1 + 255
    
    
        # Expand bounds by one-half dot width.
        # ------------------------------------
        self.pad = 5
        x1 = x1 - self.pad
        x2 = x2 + self.pad
        y1 = y1 - self.pad
        y2 = y2 + self.pad
        expanded_size = (x2-x1, y2-y1)
    
    
        # Translate new pixel bounds to lat/lng.
        # --------------------------------------
    
        n, w = gmerc.px2ll(x1, y1, zoom)
        s, e = gmerc.px2ll(x2, y2, zoom)
        self.w,self.s,self.e,self.n = w,s,e,n

        # Save
        # ====

        self.x = x
        self.y = y

        self.x1 = x1
        self.y1 = y1

        self.x2 = x2
        self.y2 = y2

        self.expanded_size = expanded_size
        self.llbound = (n,s,e,w)
        self.zoom = zoom
        self.fspath = fspath
        self.mapType= map_type
        self.mapname = mapname
Ejemplo n.º 7
0
  def __init__(self, user, zoom, x_tile, y_tile):
    self.zoom = zoom
    self.decay = 0.5
    #dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
    dot_radius = int(math.ceil((self.zoom + 1) * DOT_MULT))

    self.northwest_ll_buffered = gmerc.px2ll((x_tile    ) * 256 - dot_radius, (y_tile    ) * 256 - dot_radius, zoom)
    self.northwest_ll          = gmerc.px2ll((x_tile    ) * 256             , (y_tile    ) * 256             , zoom)

    self.southeast_ll_buffered = gmerc.px2ll((x_tile + 1) * 256 + dot_radius, (y_tile + 1) * 256 + dot_radius, zoom) #TODO fix this in case we're at the edge of the map!
    self.southeast_ll          = gmerc.px2ll((x_tile + 1) * 256             , (y_tile + 1) * 256             , zoom)

    # calculate the real values for these without the offsets, otherwise it messes up the __merge_point_in_space calculations
    self.latlng_diff_buffered = [ self.southeast_ll_buffered[0] - self.northwest_ll_buffered[0], self.southeast_ll_buffered[1] - self.northwest_ll_buffered[1]]
    self.latlng_diff          = [ self.southeast_ll[0]          - self.northwest_ll[0]         , self.southeast_ll[1]          - self.northwest_ll[1]]

    BasicTile.__init__(self, user, self.northwest_ll_buffered[0], self.northwest_ll_buffered[1], self.latlng_diff_buffered[0], self.latlng_diff_buffered[1])
Ejemplo n.º 8
0
  def __init__(self, user, zoom, lat_north, lng_west, offset_x_px, offset_y_px):
    self.zoom = zoom
    self.decay = 0.5
    #dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
    dot_radius = int(math.ceil((self.zoom + 1) * DOT_MULT)) #TODO double check that this is + 1 - because range started from 1 in old dot array?!

    # convert to pixel first so we can factor in the dot radius and get the tile bounds
    northwest_px = gmerc.ll2px(lat_north, lng_west, zoom)

    self.northwest_ll_buffered = gmerc.px2ll(northwest_px[0] + offset_x_px       - dot_radius, northwest_px[1] + offset_y_px       - dot_radius, zoom)
    self.northwest_ll          = gmerc.px2ll(northwest_px[0] + offset_x_px                   , northwest_px[1] + offset_y_px                   , zoom)

    self.southeast_ll_buffered = gmerc.px2ll(northwest_px[0] + offset_x_px + 256 + dot_radius, northwest_px[1] + offset_y_px + 256 + dot_radius, zoom)
    self.southeast_ll          = gmerc.px2ll(northwest_px[0] + offset_x_px + 256             , northwest_px[1] + offset_y_px + 256             , zoom) # THIS IS IMPORTANT TO PROPERLY CALC latlng_diff

    self.latlng_diff_buffered = [ self.southeast_ll_buffered[0] - self.northwest_ll_buffered[0], self.southeast_ll_buffered[1] - self.northwest_ll_buffered[1]]
    self.latlng_diff          = [ self.southeast_ll[0]          - self.northwest_ll[0]         , self.southeast_ll[1]          - self.northwest_ll[1]]

    BasicTile.__init__(self, user, self.northwest_ll_buffered[0], self.northwest_ll_buffered[1], self.latlng_diff_buffered[0], self.latlng_diff_buffered[1])
Ejemplo n.º 9
0
  def __init__(self, user, zoom, lat_north, lng_west, offset_x_px, offset_y_px):
    self.zoom = zoom
    self.decay = 0.5
    #dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
    dot_radius = int(math.ceil((self.zoom + 1) * DOT_MULT)) #TODO double check that this is + 1 - because range started from 1 in old dot array?!

    # convert to pixel first so we can factor in the dot radius and get the tile bounds
    northwest_px = gmerc.ll2px(lat_north, lng_west, zoom)

    self.northwest_ll_buffered = gmerc.px2ll(northwest_px[0] + offset_x_px       - dot_radius, northwest_px[1] + offset_y_px       - dot_radius, zoom)
    self.northwest_ll          = gmerc.px2ll(northwest_px[0] + offset_x_px                   , northwest_px[1] + offset_y_px                   , zoom)

    self.southeast_ll_buffered = gmerc.px2ll(northwest_px[0] + offset_x_px + 256 + dot_radius, northwest_px[1] + offset_y_px + 256 + dot_radius, zoom)
    self.southeast_ll          = gmerc.px2ll(northwest_px[0] + offset_x_px + 256             , northwest_px[1] + offset_y_px + 256             , zoom) # THIS IS IMPORTANT TO PROPERLY CALC latlng_diff

    self.latlng_diff_buffered = [ self.southeast_ll_buffered[0] - self.northwest_ll_buffered[0], self.southeast_ll_buffered[1] - self.northwest_ll_buffered[1]]
    self.latlng_diff          = [ self.southeast_ll[0]          - self.northwest_ll[0]         , self.southeast_ll[1]          - self.northwest_ll[1]]

    BasicTile.__init__(self, user, self.northwest_ll_buffered[0], self.northwest_ll_buffered[1], self.latlng_diff_buffered[0], self.latlng_diff_buffered[1])
Ejemplo n.º 10
0
 def __init__(self, layer, zoom, x, y, category, metro):
   self.layer = layer
   self.zoom = zoom
   self.x = x
   self.y = y
   self.category = category
   self.metro = metro
   self.color_scheme = color_scheme.cyan_red
   self.decay = 0.0
   self.tile_img = None
   # attempt to get a cached object
   self.tile_dump = self.__get_cached_image()
   if not self.tile_dump:
       half_size = (zoom + 1) * 3 / 2
       self.georange = gmerc.px2ll(x * 256 - half_size, y * 256 - half_size, zoom)
       self.georange_next = gmerc.px2ll((x + 1) * 256 + half_size, (y + 1) * 256 + half_size, zoom)
       self.zoom_step = [ self.georange_next[0] - self.georange[0],
       self.georange_next[1] - self.georange[1]]
       # Get the points and start plotting data
       self.tile_img = self.plot_image(
       provider.get_data(self.zoom, self.layer, 
                           self.georange[0], self.georange[1], 
                           self.zoom_step[0], self.zoom_step[1], category, metro))
Ejemplo n.º 11
0
    def __init__(self, color_scheme, dots, zoom, x, y, crime, accident, cops, fspath, mapname):
        """x and y are tile coords per Google Maps.
        """

        # Calculate some things.
        # ======================


        dotSize = zoom - 13 if zoom >= 13 else 0
        maxSize = max(crime,accident, cops)
        dotSize = 30 - maxSize if dotSize + maxSize > 30 else dotSize

        crimeDot = dots[dotSize + crime]
        accidentDot = dots[dotSize + accident]
        copsDot = dots[dotSize + cops]

        maxDot = dots[dotSize + maxSize]

        # Translate tile to pixel coords.
        # -------------------------------

        x1 = x * SIZE
        x2 = x1 + 255
        y1 = y * SIZE
        y2 = y1 + 255
    
    
        # Expand bounds by one-half dot width.
        # ------------------------------------
    
        x1 = x1 - maxDot.half_size
        x2 = x2 + maxDot.half_size
        y1 = y1 - maxDot.half_size
        y2 = y2 + maxDot.half_size
        expanded_size = (x2-x1, y2-y1)
    
        # Translate new pixel bounds to lat/lng.
        # --------------------------------------
    
        n, w = gmerc.px2ll(x1, y1, zoom)
        s, e = gmerc.px2ll(x2, y2, zoom)

        # Save
        # ====

        self.dot = {
                'ACCIDENT' : accidentDot.img,
                'CRIME' : crimeDot.img
                }

        self.pad = {
                'ACCIDENT' : accidentDot.half_size,
                'CRIME' : crimeDot.half_size
                }

        self.maxPad = maxDot.half_size

        self.x = x
        self.y = y

        self.x1 = x1
        self.y1 = y1

        self.x2 = x2
        self.y2 = y2

        self.expanded_size = expanded_size
        self.llbound = (n,s,e,w)
        self.zoom = zoom
        self.fspath = fspath
        self.opacity = gheat.opacity.zoom_to_opacity[zoom]
        self.color_scheme = color_scheme
        self.mapname = mapname