Changeset 9149
- Timestamp:
- May 5, 2011, 9:34:53 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/website/tile.py
r9148 r9149 11 11 import logging 12 12 import numpy as np 13 import settings13 import pygame 14 14 import sys 15 import pygame16 15 import tempfile 17 16 … … 23 22 def __init__(self, method, size): 24 23 self.surf = pygame.Surface(size,flags=pygame.SRCALPHA) 24 25 def center_crop(self,size): 26 """ Resize to make centered rectange from image """ 27 new_surf = pygame.Surface(size, flags=pygame.SRCALPHA) 28 curr_size = self.surf.get_size() 29 new_surf.blit(self.surf,(0,0), 30 ((curr_size[0] - size[0]) / 2, (curr_size[1] - size[1]) / 2, size[0], size[1])) 31 self.surf = new_surf 25 32 26 33 def write(self, fh,format='png'): … … 34 41 def add_circle(self, center, radius, colour=(255,0,0)): 35 42 # Quirky hack to generate lineair gradient circles and merge them with the parent. 36 new_surf = pygame.Surface( (250,250),flags=pygame.SRCALPHA)43 new_surf = pygame.Surface(self.surf.get_size(),flags=pygame.SRCALPHA) 37 44 for r in range(radius,1,-1): 38 45 pygame.draw.circle(new_surf,colour + (255 - (r * (float(255)/radius)),),center,r,0) … … 123 130 def make_tile(x,y,z): 124 131 """ Crude attempt to generate tiles, by placing a gradient circle on a 125 coordinate point. 132 coordinate point. Generate a larger tile and make sure to plot related 133 points first and then crop it to the required size (250x250). 126 134 127 135 Many stuff NOT implemented yet, like: 128 136 - Caching Images 129 - Generate a larger tile (300x300) at first and then crop it to the required130 size (250x250).131 137 """ 138 SIZE = 250 139 132 140 nw_deg,se_deg = boundbox_deg(x,y,z) 141 133 142 134 143 Picture = PyGamePicture 135 resolution_deg = nw_deg.deg_per_pixel(se_deg, 250) 136 im = Picture("RGBA",(250,250)) 144 resolution_deg = nw_deg.deg_per_pixel(se_deg, SIZE) 145 # Converting LatLon to Meters is discussed here: 146 # http://stackoverflow.com/questions/3024404/transform-longitude-latitude-into-meters 147 tile_height = float(40008000) / (2 ** z) 148 meters_per_pixel = float(tile_height) / SIZE 149 150 # Worst case scenario could a circle with 100% 'outside' our 250x250 range 151 # also add data to the picture as circles are used 152 border_pixels = 100 / meters_per_pixel / 2 153 154 im = Picture("RGBA", (SIZE + border_pixels * 2,) * 2) 155 156 nw_deg.lat += resolution_deg.lat * border_pixels 157 nw_deg.lon -= resolution_deg.lon * border_pixels 158 se_deg.lat -= resolution_deg.lat * border_pixels 159 se_deg.lon += resolution_deg.lon * border_pixels 137 160 138 161 lat_min = 999 … … 147 170 return max(x,y) - min(x,y) 148 171 149 # Converting LatLon to Meters is discussed here:150 # http://stackoverflow.com/questions/3024404/transform-longitude-latitude-into-meters151 tile_height = float(40008000) / (2 ** z)152 meters_per_pixel = float(tile_height) / 250153 172 for meting in metingen: 154 173 lat_min = min(lat_min, meting.latitude) … … 175 194 log.info("Metingen Count: %s" % metingen.count()) 176 195 196 im.center_crop((SIZE,SIZE)) 177 197 return im 178 198
Note:
See TracChangeset
for help on using the changeset viewer.