source: subversion/applications/rendering/genericHeatmapRender/locationFinder_TAHregularGrid.py @ 30554

Last change on this file since 30554 was 16229, checked in by stevefaeembra, 10 years ago

added grid and T@H heatmap code and demos

  • Property svn:mime-type set to text/plain
File size: 3.1 KB
Line 
1# -*- coding: UTF8 -*-
2'''
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License along
14    with this program; if not, write to the Free Software Foundation, Inc.,
15    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16'''
17
18from location import location
19import string
20from locationFinder import locationFinder
21import random
22import re
23
24#path to a local copy of the tiles directory dump
25#get an up-to-date copy here:-
26#http://tah.openstreetmap.org/media/filesizes.bz2
27
28LOCALCOPY = r"c:\filesizes.txt"
29
30class locationFinder_TAHregularGrid(locationFinder):
31    '''
32    Responsible for generating a list of location objects
33    this implementation generates a grid of regularly spaced
34    points (and generates random values for each)
35    '''
36           
37    def __init__(self):
38        '''
39        Constructor
40        '''
41       
42    def query(self,query=None,peturb=0.05,sampleevery=100,steps=200):
43        '''
44        generate a regular grid of points
45        from the TAH directory dump
46       
47        query is not used at present
48        steps is resolution on both axes
49        sampleevery is the random sample rate (e.g. 100=choose 1 in every 100 points)
50        set sampleevery to None to include all points
51       
52        peturb can be used to add a small random nudge to each point
53        this can improve the aesthetics when zoomed in by
54        softening the 'diamond' effect.
55        '''
56       
57        print "generating mesh"
58       
59        if sampleevery==None:
60            threshold=0.0
61        else:
62            threshold=1.0-(1.0/sampleevery)
63        bbox=self.bounds
64        xstep=float((bbox[2]-bbox[0])/float(steps))
65        ystep=float((bbox[3]-bbox[1])/float(steps))
66        maxy=int(steps)
67        maxx=int(steps)
68       
69        fi=open(LOCALCOPY)
70
71        recog=re.compile("^.*\s+.*\s+.*\s+.*\s+(?P<size>\d+)\s+.*\s+.*\s+(?P<X>\d+)[_](?P<Y>\d+)$")
72        started=False
73        for line in fi:
74            if line.find('/0000')<>-1:
75                started=True
76            if started:
77                m=recog.match(line)
78                if m:
79                    if random.random()>=threshold:
80                        x=int(m.groupdict()['X'])
81                        y=4096-int(m.groupdict()['Y'])
82                        z=int(m.groupdict()['size'])
83                        yy=bbox[1]+(y*ystep)
84                        xx=bbox[0]+(x*xstep)+(random.random()*peturb)
85                        self.addPoint('', z, xx,yy+(random.random()*peturb))
86                        #print "%s,%s,%s" % (x,y,z)
87        fi.close()
88        print 'Done mesh'
Note: See TracBrowser for help on using the repository browser.