Changeset 478

Show
Ignore:
Timestamp:
02/04/08 22:42:59 (10 months ago)
Author:
asc
Message:

dots and plots

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/py/wscompose/pinwin.py

    r476 r478  
    22 
    33__package__    = "wscompose/pinwin.py" 
    4 __version__    = "1.0
     4__version__    = "1.1
    55__author__     = "Aaron Straup Cope" 
    66__url__        = "http://www.aaronland.info/python/wscompose" 
     
    3434        if self.ctx.has_key('filter') and self.ctx['filter'] == 'atkinson' : 
    3535            img = self.atkinson_dithering(img) 
    36              
     36 
     37        # 
     38         
     39        if self.ctx.has_key('dots') : 
     40            img = self.draw_dots(img) 
     41 
     42        # 
     43         
    3744        if self.ctx.has_key('markers') : 
    3845 
     
    4451                img = self.draw_markers(img)             
    4552 
     53        # 
     54         
    4655        return img 
    4756 
     
    7180                 
    7281                self.send_header(header, sep.join(details)) 
     82 
     83        # 
     84         
     85        if self.ctx.has_key('dots') : 
     86            for data in self.ctx['dots'] : 
     87 
     88                pt = self.latlon_to_point(data['latitude'], data['longitude']) 
     89 
     90                header = "X-wscompose-Dot-%s" % data['label'] 
     91                coords = "%s,%s,%s" % (int(pt.x), int(pt.y), int(data['radius'])) 
     92                 
     93                self.send_header(header, coords) 
    7394         
    7495    # ########################################################## 
     
    235256     
    236257    # ########################################################## 
     258 
     259    # share me with marker.py or add shapes.py (or something) ? 
     260     
     261    def draw_dots (self, img) : 
     262 
     263        dr = ImageDraw.Draw(img) 
     264        pink = (255, 0, 132) 
     265        grey = (42, 42, 42) 
     266         
     267        for data in self.ctx['dots'] : 
     268 
     269            pt = self.latlon_to_point(data['latitude'], data['longitude']) 
     270            offset = float(data['radius']) / 2 
     271 
     272            x1 = pt.x - offset 
     273            y1 = pt.y - offset 
     274            x2 = pt.x + offset 
     275            y2 = pt.y + offset 
     276 
     277            dr.ellipse((x1 + 1 , y1 + 2, x2 + 1, y2 + 2), fill=grey) 
     278            dr.ellipse((x1, y1, x2, y2), fill=pink)             
     279 
     280        return img 
     281     
     282    # ########################################################## 
    237283     
    238284    def fetch_marker_fill (self, mrk_data) : 
     
    334380             
    335381        # 
     382        # dots 
     383        # 
     384 
     385        if params.has_key('dot') : 
     386 
     387            try : 
     388                valid['dots'] = validator.dots(params['dot']) 
     389            except Exception, e : 
     390                self.error(141, e) 
     391                return False 
    336392         
    337393        return valid 
     
    358414        self.help_option('point', 'A comma-separated string containing the latitude and longitude indicating the point where the marker should be placed', True, 1) 
    359415        self.help_option('dimensions', 'A comma-separated string containing the height and width of the marker canvas - the default is 75 x 75', False, 1)    
     416 
     417        self.help_option('dot', 'Draw a pinwin-style dot (but not the marker) at a given point. You may pass multiple dot arguments, each of which should contain the following comma separated values :', False) 
     418        self.help_option('label', 'A unique string to identify the dot by', True, 1) 
     419        self.help_option('point', 'A comma-separated string containing the latitude and longitude indicating the point where the dot should be placed', True, 1) 
     420        self.help_option('radius', 'The radius, in pixels, of the dot - the default is 18', False, 1)     
     421 
     422        self.help_option('plot', 'Plot -- but do not render -- the x and y coordinates for a given point. Coordinate data will be returned HTTP header(s) named \'X-wscompose-plot-\' followed by the label you choose when passing latitude and longitude information. You may pass multiple plot arguments, each of which should contain the following comma separated values :', False) 
     423        self.help_option('label', 'A unique string to identify the plotting by', True, 1) 
     424        self.help_option('point', 'A comma-separated string containing the latitude and longitude indicating the point to be plotted', True, 1) 
    360425 
    361426        self.help_option('fill', 'A helper argument which if present will cause each marker specified to be filled with the contents of map for the marker\'s coordinates at zoom level 15. The value should be a valid ModestMaps map tile provider.', False) 
     
    394459        X-wscompose-Marker-cherrier: 679,312,641,192,75,75""") 
    395460 
    396         self.help_para("Most headers are self-explanatory. Markers are a little more complicated.") 
    397  
    398         self.help_para("The string after 'X-wscompose-Marker-' is the label assigned to the marker when the API call was made. The value is a comma separated list interpreted as follows :") 
     461        self.help_para("Most headers are self-explanatory. Markers, dots and plotting coordinates are a little more complicated.") 
     462 
     463        self.help_para("The string after 'X-wscompose-darker-' is the label assigned to the marker when the API call was made. The value is a comma separated list interpreted as follows :") 
    399464 
    400465        self.help_para("The first two numbers are the x/y coordinates for the lat/lon.") 
     
    402467        self.help_para("The last pair  are the dimensions of the pinwin content which is sort of redundant unless you are opting for defaults and don't know what to expect.") 
    403468 
    404     # ########################################################## 
     469        self.help_para("'X-wscompose-dot-' headers return x and y coordinates followed by the dot's radius, in pixels") 
     470        self.help_para("'X-wscompose-plot-' headers return only x and y coordinates") 
     471         
     472    # ########################################################## 
  • trunk/py/wscompose/plotting.py

    r476 r478  
    7575             
    7676            mrk = self.load_marker(w, h, a) 
    77              
    78             loc = ModestMaps.Geo.Location(mrk_data['latitude'], mrk_data['longitude']) 
    79             pt = self.ctx['map'].locationPoint(loc)             
     77 
     78            pt = self.latlon_to_point(mrk_data['latitude'], mrk_data['longitude']) 
     79             
     80            # loc = ModestMaps.Geo.Location(mrk_data['latitude'], mrk_data['longitude']) 
     81            # pt = self.ctx['map'].locationPoint(loc)             
    8082             
    8183            # argh...fix me! 
  • trunk/py/wscompose/validate.py

    r476 r478  
    22 
    33__package__    = "wscompose/validate.py" 
    4 __version__    = "1.0
     4__version__    = "1.1
    55__author__     = "Aaron Straup Cope" 
    66__url__        = "http://www.aaronland.info/python/wscompose" 
     
    9191    # ########################################################## 
    9292 
     93    def radius (self, input) : 
     94        return self.__num(input) 
     95 
     96    # ########################################################## 
     97 
    9398    def provider (self, input) : 
    9499 
     
    209214 
    210215        return valid 
    211      
     216 
     217    # ########################################################## 
     218 
     219    def plots (self, plots) : 
     220 
     221        valid = [] 
     222 
     223        for pos in plots : 
     224 
     225            details = pos.split(",") 
     226            details = map(string.strip, details) 
     227             
     228            if len(details) < 3 : 
     229                raise Exception, "Missing or incomplete %s parameter : %s" % ('plot', pos) 
     230 
     231            data = {} 
     232             
     233            try : 
     234                data['label'] = self.marker_label(details[0]) 
     235            except Exception, e : 
     236                raise Exception, e 
     237 
     238            # Pinwin location 
     239             
     240            try : 
     241                data['latitude'] = self.latlon(details[1]) 
     242            except Exception, e : 
     243                raise Exception, e 
     244 
     245            try : 
     246                data['longitude'] = self.latlon(details[2]) 
     247            except Exception, e : 
     248                raise Exception, e 
     249 
     250            valid.append(data) 
     251 
     252        return valid 
     253             
     254    # ########################################################## 
     255 
     256    def dots (self, dots) : 
     257 
     258        valid = [] 
     259 
     260        for pos in dots : 
     261 
     262            details = pos.split(",") 
     263            details = map(string.strip, details) 
     264            cnt = len(details) 
     265             
     266            if cnt < 3 : 
     267                raise Exception, "Missing or incomplete %s parameter : %s" % ('dot', pos) 
     268 
     269            data = {} 
     270             
     271            try : 
     272                data['label'] = self.marker_label(details[0]) 
     273            except Exception, e : 
     274                raise Exception, e 
     275 
     276            # Pinwin location 
     277             
     278            try : 
     279                data['latitude'] = self.latlon(details[1]) 
     280            except Exception, e : 
     281                raise Exception, e 
     282 
     283            try : 
     284                data['longitude'] = self.latlon(details[2]) 
     285            except Exception, e : 
     286                raise Exception, e 
     287 
     288            # 
     289             
     290            if cnt > 3 : 
     291                try : 
     292                    data['radius'] = self.radius(details[3]) 
     293                except Exception, e : 
     294                    raise Exception, e 
     295 
     296            else : 
     297                data['radius'] = 18 
     298 
     299            # 
     300             
     301            if cnt > 4 : 
     302                #  fix me 
     303                pass 
     304            else : 
     305                data['colour'] = 'red' 
     306 
     307            # 
     308 
     309            valid.append(data) 
     310 
     311        return valid 
     312             
    212313    # ########################################################## 
    213314     
  • trunk/py/wscompose/__init__.py

    r476 r478  
    22 
    33__package__    = "wscompose/__init__.py" 
    4 __version__    = "1.0
     4__version__    = "1.1
    55__author__     = "Aaron Straup Cope" 
    66__url__        = "http://www.aaronland.info/python/wscompose" 
     
    3434    def __init__ (self, request, client_address, server) : 
    3535        self.ctx = {} 
     36        self.points = {} 
    3637        BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, client_address, server) 
    3738         
     
    239240        self.send_header("X-wscompose-Image-Width", img.size[0])         
    240241        self.send_header("X-wscompose-Map-Zoom", self.ctx['zoom']) 
     242 
     243        if self.ctx.has_key('plot') : 
     244            for data in self.ctx['plot'] : 
     245 
     246                pt = self.latlon_to_point(data['latitude'], data['longitude']) 
     247 
     248                header = "X-wscompose-Plot-%s" % data['label'] 
     249                coords = "%s,%s" % (int(pt.x), int(pt.y)) 
     250 
     251                self.send_header(header, coords) 
    241252                 
     253    # ########################################################## 
     254 
     255    def latlon_to_point (self, lat, lon) : 
     256 
     257        key = "%s-%s" % (lat, lon) 
     258 
     259        if not self.points.has_key(key) : 
     260            loc = ModestMaps.Geo.Location(lat, lon) 
     261            pt = self.ctx['map'].locationPoint(loc) 
     262            self.points[key] = pt 
     263 
     264        return self.points[key] 
     265     
    242266    # ########################################################## 
    243267     
     
    410434                    return False 
    411435             
     436 
     437        # 
     438        # plotting or "headless" markers 
     439        # 
     440 
     441        if params.has_key('plot') : 
     442 
     443            try : 
     444                valid['plot'] = validator.plots(params['plot']) 
     445            except Exception, e : 
     446                self.error(141, e) 
     447                return False 
     448         
    412449        # 
    413450        # whoooosh 
     
    474511        self.help_option('bbox', 'A bounding box comprised of comma-separated decimal coordinates in the following order : SW latitude, SW longitude, NE latitude, NE longitude', True, 2) 
    475512        self.help_option('accuracy', 'The zoom level / accuracy (as defined by ModestMaps rather than any individual tile provider) of the final image.', True, 2) 
     513 
     514        self.help_option('plot', 'Plot -- but do not render -- the x and y coordinates for a given point. Coordinate data will be returned HTTP header(s) named \'X-wscompose-plot-\' followed by the label you choose when passing latitude and longitude information. You may pass multiple plot arguments, each of which should contain the following comma separated values :', False) 
     515        self.help_option('label', 'A unique string to identify the plotting by', True, 1) 
     516        self.help_option('point', 'A comma-separated string containing the latitude and longitude indicating the point to be plotted', True, 1) 
    476517         
    477518    # ########################################################## 
     
    490531        X-wscompose-Image-Height: 1024 
    491532        X-wscompose-Image-Width: 1024 
    492         X-wscompose-Map-Zoom: 14.0""") 
     533        X-wscompose-Map-Zoom: 14.0 
     534        X-wscompose-plot-roy: 667,285""") 
     535 
     536        self.help_para("Most headers are self-explanatory. Markers, dots and plotting coordinates are a little more complicated.") 
     537 
     538        self.help_para("The string after 'X-wscompose-plot-' is the label assigned to the marker when the API call was made. The value is a comma separated list containing the x and y coordinates for (label's) corresponding latitude and longitude.") 
    493539         
    494540    # ##########################################################