Exemplo n.º 1
0
def preview_url(ul, ur, lr, ll):
    '''
    '''
    merc = MercatorProjection(0)

    ul = merc.rawUnproject(Point(*ul))
    ur = merc.rawUnproject(Point(*ur))
    lr = merc.rawUnproject(Point(*lr))
    ll = merc.rawUnproject(Point(*ll))

    q = dict(width='512', height='384', module='map')

    ulx, uly, urx, ury, lrx, lry, llx, lly \
        = [rad2deg(v) for v in (ul.x, ul.y, ur.x, ur.y, lr.x, lr.y, ll.x, ll.y)]

    xmin, ymin = min(ulx, urx, lrx, llx), min(uly, ury, lry, lly)
    xmax, ymax = max(uly, ury, lry, lly), max(ulx, urx, lrx, llx)
    perimeter = (ulx, uly, urx, ury, lrx, lry, llx, lly, ulx, uly)

    q.update(dict(polygons=','.join(['%.4f' % v for v in perimeter])))
    q.update(
        dict(bbox=','.join(('%.4f' % xmin, '%.4f' % ymax, '%.4f' % xmax,
                            '%.4f' % ymin))))

    return 'http://pafciu17.dev.openstreetmap.org/?' + urlencode(q)
Exemplo n.º 2
0
def calculate_corners(aspect, x, y, size, theta):
    ''' Return latitude, longitude corners for a geometric placement.
    '''
    merc = MercatorProjection(0)
    
    #
    # Get the natural angle of the hypotenuse from map aspect ratio,
    # measured from the lower-right to the upper-left corner and expressed
    # in CCW radians from due east.
    #
    base_theta = atan2(1, -float(aspect))
    
    #
    # Derive center-to-corners offset from natural angle and placement theta.
    #
    place_theta = base_theta + theta
    
    dx = sin(place_theta - pi/2) * size/2
    dy = cos(place_theta - pi/2) * size/2

    ul = Point(x - dx, y + dy)
    lr = Point(x + dx, y - dy)
    
    #
    # Convert back to degree latitude and longitude
    #
    ul = merc.rawUnproject(ul)
    lr = merc.rawUnproject(lr)
    
    ul_lat, ul_lon = rad2deg(ul.y), rad2deg(ul.x)
    lr_lat, lr_lon = rad2deg(lr.y), rad2deg(lr.x)
    
    return ul_lat, ul_lon, lr_lat, lr_lon
Exemplo n.º 3
0
def preview_url(ul, ur, lr, ll):
    '''
    '''
    merc = MercatorProjection(0)
    
    ul = merc.rawUnproject(Point(*ul))
    ur = merc.rawUnproject(Point(*ur))
    lr = merc.rawUnproject(Point(*lr))
    ll = merc.rawUnproject(Point(*ll))
    
    q = dict(width='512', height='384', module='map')

    ulx, uly, urx, ury, lrx, lry, llx, lly \
        = [rad2deg(v) for v in (ul.x, ul.y, ur.x, ur.y, lr.x, lr.y, ll.x, ll.y)]

    xmin, ymin = min(ulx, urx, lrx, llx), min(uly, ury, lry, lly)
    xmax, ymax = max(uly, ury, lry, lly), max(ulx, urx, lrx, llx)
    perimeter = (ulx, uly, urx, ury, lrx, lry, llx, lly, ulx, uly)

    q.update(dict(polygons=','.join(['%.4f' % v for v in perimeter])))
    q.update(dict(bbox=','.join(('%.4f' % xmin, '%.4f' % ymax, '%.4f' % xmax, '%.4f' % ymin))))
    
    return 'http://pafciu17.dev.openstreetmap.org/?' + urlencode(q)