Changeset 10615 for src/django_gheat
- Timestamp:
- Apr 29, 2012, 7:59:27 PM (13 years ago)
- Location:
- src/django_gheat
- Files:
-
- 10 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/__init__.py
r9145 r10615 1 import logging2 import os3 4 from gheat import gheatsettings as settings5 6 from django.core.exceptions import ImproperlyConfigured7 from django.db import connection8 9 # Logging config10 # ==============11 12 if settings.DEBUG:13 level = logging.WARNING14 else:15 level = logging.WARNING16 if os.getenv('DEBUG', None):17 level = logging.DEBUG18 19 logging.basicConfig(level=level) # Ack! This should be in Aspen. :^(20 log = logging.getLogger('gheat')21 22 23 # Configuration24 # =============25 # Set some things that backends will need.26 ALWAYS_BUILD = settings.GHEAT_ALWAYS_BUILD = False27 BUILD_EMPTIES = settings.GHEAT_BUILD_EMPTIES = False28 29 DIRMODE = settings.GHEAT_DIRMODE30 try:31 DIRMODE = int(eval(DIRMODE))32 except (NameError, SyntaxError, ValueError):33 raise ImproperlyConfigured("dirmode (%s) must be an integer." % dirmode)34 35 SIZE = 256 # size of (square) tile; NB: changing this will break gmerc calls!36 MAX_ZOOM = 22 # this depends on Google API; 0 is furthest out as of recent ver.37 38 39 # Try to find an image library.40 # =============================41 42 BACKEND = None43 BACKEND_PIL = False44 BACKEND_PYGAME = False45 46 _want = settings.GHEAT_BACKEND.lower()47 if _want not in ('pil', 'pygame', ''):48 raise ImproperlyConfigured( "The %s backend is not supported, only PIL and "49 + "Pygame (assuming those libraries are installed)."50 )51 52 if _want:53 if _want == 'pygame':54 from gheat import pygame_ as backend55 elif _want == 'pil':56 from gheat import pil_ as backend57 BACKEND = _want58 else:59 try:60 from gheat import pygame_ as backend61 BACKEND = 'pygame'62 except ImportError:63 try:64 from gheat import pil_ as backend65 BACKEND = 'pil'66 except ImportError:67 raise68 pass69 70 if BACKEND is None:71 raise ImportError("Neither Pygame nor PIL could be imported.")72 73 BACKEND_PYGAME = BACKEND == 'pygame'74 BACKEND_PIL = BACKEND == 'pil'75 76 log.info("Using the %s library" % BACKEND)77 78 79 # Set up color schemes and dots.80 # ==============================81 82 color_schemes = dict() # this is used below83 84 _color_schemes_dir = os.path.join(settings.GHEAT_CONF_DIR, 'color-schemes')85 for fname in os.listdir(_color_schemes_dir):86 if not fname.endswith('.png'):87 continue88 name = os.path.splitext(fname)[0]89 fspath = os.path.join(_color_schemes_dir, fname)90 color_schemes[name] = backend.ColorScheme(name, fspath)91 92 def load_dots(backend):93 """Given a backend module, return a mapping of zoom level to Dot object.94 """95 return dict([(zoom, backend.Dot(zoom)) for zoom in range(MAX_ZOOM)])96 dots = load_dots(backend) # factored for easier use from scripts97 98 # Some util methods99 # =================100 def translate(root, url):101 """Translate a URL to the filesystem.102 103 We specifically avoid removing symlinks in the path so that the filepath104 remains under the website root. Also, we don't want trailing slashes for105 directories.106 107 """108 parts = [root] + url.lstrip('/').split('/')109 return os.sep.join(parts).rstrip(os.sep)110 111 ROOT = settings.GHEAT_MEDIA_ROOT -
src/django_gheat/gheat/urls.py
r9006 r10615 1 # -*- coding: utf-8 -*-2 from django.conf.urls.defaults import *3 4 urlpatterns = patterns('gheat.views',5 url(6 # Example : today/fire/12/3,2.png7 regex = r'^(?P<color_scheme>\w+)/(?P<zoom>\d+)/(?P<x>\d+),(?P<y>\d+).png$',8 view = 'serve_tile',9 name = 'serve_tile',10 ),11 ) -
src/django_gheat/httpd/maps.conf
r9556 r10615 14 14 RedirectMatch temp ^/$ /d/wlheatmap/ 15 15 Alias /d/static /usr/local/django_gheat/sitestatic 16 WSGIDaemonProcess maps processes=2 threads=15 display-name=%{GROUP} 17 WSGIProcessGroup maps 16 18 WSGIScriptAlias /d /usr/local/django_gheat/django.wsgi 17 19 <Directory /usr/local/django_gheat> -
src/django_gheat/httpd/osmproxy.conf
r9556 r10615 18 18 </Proxy> 19 19 # Example /7/63/43.png 20 <Location /osm-tile-proxy> 21 Order allow,deny 22 Allow from all 23 </Location> 20 24 ProxyPassMatch ^/osm-tile-proxy/(\d{1,2}/\d{1,6}/\d{1,6}\.png)$ balancer://osmcluster/$1 lbmethod=byrequests 21 25 CacheEnable disk /osm-tile-proxy/ -
src/django_gheat/wlheatmap/tile.py
r9662 r10615 16 16 import time 17 17 18 # Rending with PIL and computation with numpy has proven to be to slow to be19 # usable, but is still in here for refence purposes.20 try:21 from PIL import Image22 import ImageDraw23 import numpy as np24 except ImportError:25 pass26 18 27 19 class PyGamePicture(): … … 70 62 pygame.draw.circle(new_surf,combined_colour,center,r,0) 71 63 self.surf.blit(new_surf,(0,0),special_flags=pygame.BLEND_RGBA_MAX) 72 73 74 class PILPicture():75 """ Basic PIL class, allowing simple image manipulations """76 im = None77 def __init__(self, method, size):78 self.im = Image.new(method, size)79 self.data = np.array(self.im)80 81 def write(self,fh,format='png'):82 self.im.save(fh,format)83 84 def make_circle(self,draw, center, radius,colour=(0,255,0)):85 """ Cicle gradient is created by creating smaller and smaller cicles """86 (center_x, center_y) = center87 for i in range(0,radius):88 draw.ellipse(89 (center_x - radius + i,90 center_y - radius + i,91 center_x + radius - i,92 center_y + radius - i93 ),94 colour +(255 * i/(radius * 2),)95 )96 97 def add_circle(self, center, radius, colour):98 """ Adding a new cicle is a matter of creating a new one in a empty layer99 and merging it with the current one100 101 XXX: Very heavy code, should actually only work on the data arrays, instead102 of doing all the magic with high-level images """103 104 im_new = Image.new("RGBA", self.im.size)105 draw = ImageDraw.Draw(im_new)106 self.make_circle(draw, center, radius, colour)107 108 data2 = np.array(im_new)109 110 # Add channels to make new images111 self.data = self.data + data2112 self.im = Image.fromarray(self.data)113 114 64 115 65
Note:
See TracChangeset
for help on using the changeset viewer.