Пример #1
0
    def __init__(self):
        pi = _pi

        # Transform from raw mercator projection to tile coordinates
        t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)

        MercatorProjection.__init__(self, 0, t)
Пример #2
0
    def __init__(self):
        p = _pi

        # Transform from geography in radians to tile coordinates
        t = deriveTransformation(-p, p/2, 0, 0, p, p/2, 2, 0, -p, -p/2, 0, 1)

        LinearProjection.__init__(self, 0, t)
Пример #3
0
    def __init__(self):
        p = _pi

        # Transform from geography in radians to tile coordinates
        t = deriveTransformation(-p, p/2, 0, 0, p, p/2, 2, 0, -p, -p/2, 0, 1)

        LinearProjection.__init__(self, 0, t)
Пример #4
0
    def __init__(self):
        pi = _pi

        # Transform from raw mercator projection to tile coordinates
        t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)

        MercatorProjection.__init__(self, 0, t)
Пример #5
0
 def __init__(self):
     t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
     self.projection = MercatorProjection(0, t)
Пример #6
0
def get_projection():
    ''' Return the correct spherical mercator project for Nokia.
    '''
    # the spherical mercator world tile covers (-π, -π) to (π, π)
    t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
    return MercatorProjection(0, t)
Пример #7
0
def generate_map_tiles(mysql, bucket, map_id):
    '''
    '''
    mysql.execute('''SELECT * FROM maps WHERE id = %s''', (map_id, ))
    map = mysql.fetchdict()
    
    #
    # Retrieve the original uploaded image from storage.
    #
    
    img = bucket.get_key(map['image'])
    if not img:
        # started using unqoute_plus to name the keys, to handle double encoding of file names on S3
        img = bucket.get_key(unquote_plus(map['image']))
    
    # ok give up
    if not img:
        logging.error("No image found for map: %s"%(map['id']))
        return 
    
    
    tmpdir = mkdtemp(prefix='gen-map-tiles-')
    imgname = join(tmpdir, basename(img.name))
    
    img.get_contents_to_filename(imgname)
    img = Image.open(imgname)
    w, h = img.size
    
    #
    # Calculate a geo transformation based on three corner points.
    #
    size, theta, (ul, ur, lr, ll) \
        = build_rough_placement_polygon(map['aspect'], map['ul_lat'], map['ul_lon'], map['lr_lat'], map['lr_lon'])
    
    logging.info(preview_url(ul, ur, lr, ll))
    
    ul = terra.transform(Point(*ul))
    ur = terra.transform(Point(*ur))
    ll = terra.transform(Point(*ll))
    lr = terra.transform(Point(*lr))
    
    args = (0, 0, ul.x, ul.y, 0, h, ll.x, ll.y, w, h, lr.x, lr.y)
    xform = deriveTransformation(*args)
    
    #
    # Build a VRT file in spherical mercator projection.
    #
    vrtname = join(tmpdir, 'image.vrt')
    vrt = build_vrt(basename(imgname), img.size[0], img.size[1], xform)
    vrt.write(open(vrtname, 'w'))
    
    key = bucket.new_key(join(dirname(map['image']), 'image.vrt'))
    key.set_contents_from_filename(vrtname, {'Content-Type': 'application/gdal-vrt+xml'}, policy='public-read')
    
    #
    # Generate image tiles and upload them.
    #
    queue = JoinableQueue()
    tiles = join(dirname(map['image']), 'tiles')

    uploader1 = Process(target=upload_map_tiles, args=(queue, bucket, tiles))
    uploader2 = Process(target=upload_map_tiles, args=(queue, bucket, tiles))
    
    uploader1.start()
    uploader2.start()
    
    max_zoom = round(1 + native_zoom(w, h, ul, lr))
    logging.info("max_zoom from native_zoom: %s"%(max_zoom))
    # cap zoom at 18
    max_zoom = min(max_zoom,18.0)
    cut_map_tiles(vrtname, queue, ul, ur, lr, ll, max_zoom)
    
    uploader1.join()
    uploader2.join()
    
    #
    # Clean up.
    #
    rmtree(tmpdir)
    
    logging.info('Set %s on %s' % (repr(dict(tiles=basename(tiles))), map['id']))
    
    mysql.execute('UPDATE maps SET tiles = %s WHERE id = %s', (tiles, map['id']))
Пример #8
0
def get_projection():
    ''' Return the correct spherical mercator project for Nokia.
    '''
    # the spherical mercator world tile covers (-π, -π) to (π, π)
    t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
    return MercatorProjection(0, t)
Пример #9
0
 def __init__(self):
     t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
     self.projection = MercatorProjection(0, t)
Пример #10
0
 def __init__(self):
     # the spherical mercator world tile covers (-π, -π) to (π, π)
     t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
     self.projection = MercatorProjection(0, t)
Пример #11
0
def generate_map_tiles(mysql, bucket, map_id):
    '''
    '''
    mysql.execute('''SELECT * FROM maps WHERE id = %s''', (map_id, ))
    map = mysql.fetchdict()

    #
    # Retrieve the original uploaded image from storage.
    #

    img = bucket.get_key(map['image'])
    if not img:
        # started using unqoute_plus to name the keys, to handle double encoding of file names on S3
        img = bucket.get_key(unquote_plus(map['image']))

    # ok give up
    if not img:
        logging.error("No image found for map: %s" % (map['id']))
        return

    tmpdir = mkdtemp(prefix='gen-map-tiles-')
    imgname = join(tmpdir, basename(img.name))

    img.get_contents_to_filename(imgname)
    img = Image.open(imgname)
    w, h = img.size

    #
    # Calculate a geo transformation based on three corner points.
    #
    size, theta, (ul, ur, lr, ll) \
        = build_rough_placement_polygon(map['aspect'], map['ul_lat'], map['ul_lon'], map['lr_lat'], map['lr_lon'])

    logging.info(preview_url(ul, ur, lr, ll))

    ul = terra.transform(Point(*ul))
    ur = terra.transform(Point(*ur))
    ll = terra.transform(Point(*ll))
    lr = terra.transform(Point(*lr))

    args = (0, 0, ul.x, ul.y, 0, h, ll.x, ll.y, w, h, lr.x, lr.y)
    xform = deriveTransformation(*args)

    #
    # Build a VRT file in spherical mercator projection.
    #
    vrtname = join(tmpdir, 'image.vrt')
    vrt = build_vrt(basename(imgname), img.size[0], img.size[1], xform)
    vrt.write(open(vrtname, 'w'))

    key = bucket.new_key(join(dirname(map['image']), 'image.vrt'))
    key.set_contents_from_filename(
        vrtname, {'Content-Type': 'application/gdal-vrt+xml'},
        policy='public-read')

    #
    # Generate image tiles and upload them.
    #
    queue = JoinableQueue()
    tiles = join(dirname(map['image']), 'tiles')

    uploader1 = Process(target=upload_map_tiles, args=(queue, bucket, tiles))
    uploader2 = Process(target=upload_map_tiles, args=(queue, bucket, tiles))

    uploader1.start()
    uploader2.start()

    max_zoom = round(1 + native_zoom(w, h, ul, lr))
    logging.info("max_zoom from native_zoom: %s" % (max_zoom))
    # cap zoom at 18
    max_zoom = min(max_zoom, 18.0)
    cut_map_tiles(vrtname, queue, ul, ur, lr, ll, max_zoom)

    uploader1.join()
    uploader2.join()

    #
    # Clean up.
    #
    rmtree(tmpdir)

    logging.info('Set %s on %s' %
                 (repr(dict(tiles=basename(tiles))), map['id']))

    mysql.execute('UPDATE maps SET tiles = %s WHERE id = %s',
                  (tiles, map['id']))