Example #1
0
def gen_metatile(metatile_id, this_layer):
    # renderlock.acquire()
    z, x, y = metatile_id
    z -= 3
    wh = 2560
    bb1 = projections.coords_by_tile(z, x - 0.125, y - 0.125, "EPSG:3857")
    bb2 = projections.coords_by_tile(z, x + 1.125, y + 1.125, "EPSG:3857")
    bbox = (bb1[0], bb2[1], bb2[0], bb1[1])
    db = DataBackend()
    res = RasterTile(wh, wh, 1, db, "EPSG:3857")
    res.update_surface(bbox, z + 3, style)
    f = NamedTemporaryFile()
    f.close()
    res.surface.write_to_png(f.name)
    del res
    del db
    im = Image.open(f.name)
    os.unlink(f.name)
    im = im.convert("RGBA")
    x *= 8
    y *= 8
    z += 3
    ext = this_layer["ext"]
    for i in range(x, x + 9):
        for j in range(y, y + 9):
            local = config.tiles_cache + this_layer["prefix"] + "/z%s/%s/x%s/%s/y%s." % (z, i / 1024, i, j / 1024, j)
            box = (256 * (i - x + 1), 256 * (j - y + 1), 256 * (i - x + 2), 256 * (j - y + 2))
            im1 = im.crop(box)
            if not os.path.exists("/".join(local.split("/")[:-1])):
                os.makedirs("/".join(local.split("/")[:-1]))
            im1.save(local + ext)
            del im1
Example #2
0
def gen_metatile(metatile_id, this_layer):
    # renderlock.acquire()
    z, x, y = metatile_id
    z -= 3
    wh = 2560
    bb1 = projections.coords_by_tile(z, x - 0.125, y - 0.125, "EPSG:3857")
    bb2 = projections.coords_by_tile(z, x + 1.125, y + 1.125, "EPSG:3857")
    bbox = (bb1[0], bb2[1], bb2[0], bb1[1])
    db = DataBackend()
    res = RasterTile(wh, wh, 1, db, "EPSG:3857")
    res.update_surface(bbox, z + 3, style)
    f = NamedTemporaryFile()
    f.close()
    res.surface.write_to_png(f.name)
    del res
    del db
    im = Image.open(f.name)
    os.unlink(f.name)
    im = im.convert("RGBA")
    x *= 8
    y *= 8
    z += 3
    ext = this_layer["ext"]
    for i in range(x, x + 9):
        for j in range(y, y + 9):
            local = config.tiles_cache + this_layer[
                "prefix"] + "/z%s/%s/x%s/%s/y%s." % (z, i / 1024, i, j / 1024,
                                                     j)
            box = (256 * (i - x + 1), 256 * (j - y + 1), 256 * (i - x + 2),
                   256 * (j - y + 2))
            im1 = im.crop(box)
            if not os.path.exists("/".join(local.split("/")[:-1])):
                os.makedirs("/".join(local.split("/")[:-1]))
            im1.save(local + ext)
            del im1
Example #3
0
def twms_main(req):
    resp = ""
    data = req
    srs = data.get("srs", data.get("SRS", "EPSG:4326"))
    content_type = "image/png"
    #layer = data.get("layers",data.get("LAYERS", config.default_layers)).split(",")

    width=0
    height=0
    req_bbox = ()
    if data.get("bbox",data.get("BBOX",None)):
      req_bbox = tuple(map(float,data.get("bbox",data.get("BBOX",req_bbox)).split(",")))

    req_bbox = projections.to4326(req_bbox, srs)

    req_bbox, flip_h = bbox.normalize(req_bbox)
    box = req_bbox

    height = int(data.get("height",data.get("HEIGHT",height)))
    width = int(data.get("width",data.get("WIDTH",width)))

    z = bbox.zoom_for_bbox (box, (height, width), {"proj":"EPSG:3857"}, min_zoom = 1, max_zoom = 25,max_size = (10000,10000))

    res = RasterTile(width, height, z, db)
    res.update_surface(box, z, style)
    image_content = StringIO.StringIO()


    
    res.surface.write_to_png(image_content)
  


    resp = image_content.getvalue()
    return (OK, content_type, resp)
Example #4
0
def kothic_fetcher(z, x, y, this_layer):
    if "max_zoom" in this_layer:
        if z >= this_layer["max_zoom"]:
            return None
    bbox = projections.bbox_by_tile(z, x, y, "EPSG:3857")
    db = DataBackend(path="/home/kom/osm/kothic/src/tiles")
    res = RasterTile(256, 256, 1, db, "EPSG:3857")
    res.update_surface(bbox, z, style)
    f = NamedTemporaryFile()
    f.close()
    res.surface.write_to_png(f.name)
    del res
    del db
    im = Image.open(f.name)
    os.unlink(f.name)
    im = im.convert("RGBA")

    return im
Example #5
0
def kothic_fetcher(z, x, y, this_layer):
    if "max_zoom" in this_layer:
        if z >= this_layer["max_zoom"]:
            return None
    bbox = projections.bbox_by_tile(z, x, y, "EPSG:3857")
    db = DataBackend(path="/home/kom/osm/kothic/src/tiles")
    res = RasterTile(256, 256, 1, db, "EPSG:3857")
    res.update_surface(bbox, z, style)
    f = NamedTemporaryFile()
    f.close()
    res.surface.write_to_png(f.name)
    del res
    del db
    im = Image.open(f.name)
    os.unlink(f.name)
    im = im.convert("RGBA")

    return im
Example #6
0
svg = False

if svg:
    import cairo


style = MapCSS(1, 19)     #zoom levels
style.parse(open("styles/default.mapcss","r").read())


bbox = (27.115768874532,53.740327031764,28.028320754378,54.067187302158)

w,h = 630*4,364*4
z = 10

db = DataBackend()
#style = Styling()

res = RasterTile(w, h, z, db)
if svg:
    file = open("test.svg", "wb")
    res.surface = cairo.SVGSurface(file.name, w,h)
res.update_surface(bbox, z, style)


if not svg:
    res.surface.write_to_png("test.png")
else:
    res.surface.finish()
Example #7
0
#from style import Styling
from mapcss import MapCSS

from render import RasterTile

svg = False

if svg:
    import cairo

style = MapCSS(1, 19)  #zoom levels
style.parse(open("styles/default.mapcss", "r").read())

bbox = (27.115768874532, 53.740327031764, 28.028320754378, 54.067187302158)

w, h = 630 * 4, 364 * 4
z = 10

db = DataBackend()
#style = Styling()

res = RasterTile(w, h, z, db)
if svg:
    file = open("test.svg", "wb")
    res.surface = cairo.SVGSurface(file.name, w, h)
res.update_surface(bbox, z, style)

if not svg:
    res.surface.write_to_png("test.png")
else:
    res.surface.finish()
Example #8
0
        self.callback = callback
        self.onscreen = set()
        self._singlethread = False
        self._prerender = True

    def __getitem__(self, (z, x, y), wait=False):

        try:
            # if "surface" in self.tiles[(z,x,y)] and not wait:
            #  self._callback((z,x,y), True)
            print "Tiles count:", len(self.tiles)
            return self.tiles[(z, x, y)]["surface"]
        except:
            self.tiles[(z, x, y)] = {
                "tile":
                RasterTile(self.tilewidth, self.tileheight, z,
                           self.data_backend)
            }
            self.tiles[(z, x, y)]["start_time"] = datetime.datetime.now()
            if self._singlethread:

                self.tiles[(z, x,
                            y)]["surface"] = self.tiles[(z, x,
                                                         y)]["tile"].surface
                self.tiles[(z, x, y)]["tile"].update_surface(
                    projections.bbox_by_tile(z, x, y, "EPSG:3857"),
                    z,
                    self.style_backend,
                    lambda p=False: self._callback((z, x, y), p))

                del self.tiles[(z, x, y)]["tile"]
            else: