Changeset 9150 for src/django_gheat/website/tile.py
- Timestamp:
- May 5, 2011, 9:54:10 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/website/tile.py
r9149 r9150 1 1 #!/usr/bin/env python 2 2 # 3 # Hack to show image generation realtime, sample tile server implementation 3 # Hack to show image generation realtime, sample tile server implementation. 4 4 # 5 5 # Rick van der Zwet <info@rickvanderzwet.nl> 6 from PIL import Image7 6 from django.core.management import setup_environ 8 7 from django.http import HttpResponse 9 8 from gheat.models import * 10 import ImageDraw11 9 import logging 12 import numpy as np13 10 import pygame 14 11 import sys 15 12 import tempfile 13 14 # Rending with PIL and computation with numpy has proven to be to slow to be 15 # usable, but is still in here for refence purposes. 16 try: 17 from PIL import Image 18 import ImageDraw 19 import numpy as np 20 except ImportError: 21 pass 16 22 17 23 logging.basicConfig(level=logging.WARNING) … … 129 135 130 136 def make_tile(x,y,z): 131 """ Crude attempt to generate tiles, by placing a gradient circle on a 137 """ 138 Crude attempt to generate tiles, by placing a gradient circle on a 132 139 coordinate point. Generate a larger tile and make sure to plot related 133 140 points first and then crop it to the required size (250x250). 134 141 135 142 Many stuff NOT implemented yet, like: 136 - Caching Images 143 - Caching Images. 144 - Conditional Filtering of Meting to allow display of sub-results. 145 - Defining a extra level of transparency if you like to layer multiple tiles 146 on top of each-other. 147 - Color variation, allow the user to dynamically choose a the colour the 148 points to be. 149 - Advanced data plotting, like trying to guess the remainder points. 137 150 """ 151 138 152 SIZE = 250 139 153 … … 163 177 lat_max = 0 164 178 lon_max = 0 179 180 # TODO: This is currently hard-coded to display _all_ metingen 165 181 metingen = Meting.objects.select_related().filter( 166 182 latitude__lte=nw_deg.lat,latitude__gte=se_deg.lat, … … 168 184 169 185 def dif(x,y): 186 """ Return difference between two points """ 170 187 return max(x,y) - min(x,y) 171 188 … … 178 195 ycoord = dif(nw_deg.lat,meting.latitude) / (resolution_deg.lat) 179 196 log.info(meting.accespoint.ssid, meting.latitude, meting.longitude, xcoord, ycoord) 180 # The radius relates to the zoom-level we are in, and should represent 197 198 # XXX: The radius relates to the zoom-level we are in, and should represent 181 199 # a fixed distance, given the scale. Assume signal/distance to be lineair 182 200 # such that signal 100% = 100m and 1% = 1m. … … 184 202 # XXX: The relation is not lineair but from a more logeritmic scape, as we 185 203 # are dealing with radio signals 204 # 205 # TODO: Please note that this 'logic' technically does any apply to WiFi signals, 206 # if you are plotting from the 'source'. With measured data you get 207 # different patterns. 208 # 186 209 im.add_circle((xcoord,ycoord),float(meting.signaal) / meters_per_pixel,(255,0,0)) 187 210 … … 204 227 im.write(response,'png') 205 228 return response 206 207 if __name__ == '__main__':208 log.setLevel(logging.DEBUG)209 x = int(sys.argv[1])210 y = int(sys.argv[2])211 z = 14212 213 im = make_tile(x,y,z)214 filename = 'sample-gradient.png'215 im.write(open(filename,'w'))216 log.info("Output saved as '%s'" % filename)
Note:
See TracChangeset
for help on using the changeset viewer.