Changeset 4072 for cows


Ignore:
Timestamp:
29/07/08 13:55:09 (11 years ago)
Author:
spascoe
Message:

Improved bbox_util functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cows/trunk/cows/bbox_util.py

    r4008 r4072  
    66 
    77""" 
     8 
     9import math 
    810 
    911def intersection(bbox1, bbox2): 
     
    3133    return (sx, sy) 
    3234 
    33 def geoToPixel(x_g, y_g, bbox, width, height): 
     35def geoToPixel(x_g, y_g, bbox, width, height, roundUpX=False, roundUpY=False): 
    3436    """ 
    3537    Calculate the pixel coordinate of a point within a bbox given the 
     
    4446    @param width: The width of the image in pixels 
    4547    @param height: The height of the image in pixels. 
     48    @param roundUpX: Round the X pixel value upwards. 
     49    @param roundUpY: Round the y pixel value upwards. 
     50     
    4651    @return: (x,y) in pixel coordinates 
    4752 
     
    5055    x = (x_g - bbox[0])*width / (bbox[2]-bbox[0]) 
    5156    y = (bbox[3] - y_g)*height / (bbox[3]-bbox[1]) 
     57 
     58    if roundUpX: 
     59        x = math.ceil(x) 
     60    if roundUpY: 
     61        y = math.ceil(y) 
    5262 
    5363    return int(x), int(y) 
Note: See TracChangeset for help on using the changeset viewer.