Exemplo n.º 1
0
def render_tile(z,x,y,db,coastlines=False):
    callback = "onKothicDataResponse"
    bbox = projections.bbox_by_tile(z+1,x,y,"EPSG:3857")
    style = MapCSS(0,30)
    style.parse(open(os.path.join(os.path.dirname(__file__),"server.mapcss"),"r").read())
    zoom = z+2
    if coastlines is True:
       tiledata = get_vectors(db,bbox,zoom,style,"coastline")
       tiledata["features"].extend(get_vectors(db,bbox,zoom,style,"polygon")["features"])
    else:
		tiledata = get_vectors(db,bbox,zoom,style,"polygon")
    tiledata["features"].extend(get_vectors(db,bbox,zoom,style,"line")["features"])
    tiledata["features"].extend(get_vectors(db,bbox,zoom,style,"point")["features"])

    tiledata = callback+"("+json.dumps(tiledata,True,False,separators=(',', ':'))+",%s,%s,%s);"%(z,x,y)
    return tiledata
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
def get_tile(x, y, z, conf):
  if z>conf['maxz']:
    return
  style = conf['style']
  callback = "onKothicDataResponse"
  connect_string = "dbname=" + conf['dbname'] + " user="******"EPSG:3857")
  
  zoom = z+2
#aaaa = get_vectors(database,bbox,zoom,style,"coastline")
  aaaa = get_vectors(database,bbox,zoom,style,"polygon")
  aaaa["features"].extend(get_vectors(database,bbox,zoom,style,"polygon")["features"])
  aaaa["features"].extend(get_vectors(database,bbox,zoom,style,"line")["features"])
#  aaaa["features"].extend(get_vectors(database,bbox,zoom,style,"point")["features"])

  aaaa = callback+"("+json.dumps(aaaa,True,False,separators=(',', ':'))+",%s,%s,%s);"%(z,x,y)
  return aaaa
Exemplo n.º 5
0
    print "need z"
    exit()
if "x" not in form:
    print "need x"
    exit()
if "y" not in form:
    print "need y"
    exit()
z = int(form["z"].value)
x = int(form["x"].value)
y = int(form["y"].value)
if z > 22:
    exit()
callback = "onKothicDataResponse"

bbox = projections.bbox_by_tile(z + 1, x, y, "EPSG:3857")

style = MapCSS(0, 30)
style.parse(open("styles/osmosnimki-maps.mapcss", "r").read())
zoom = z + 2
aaaa = get_vectors(bbox, zoom, style, "coastline")
aaaa["features"].extend(get_vectors(bbox, zoom, style, "polygon")["features"])
aaaa["features"].extend(get_vectors(bbox, zoom, style, "line")["features"])
aaaa["features"].extend(get_vectors(bbox, zoom, style, "point")["features"])

aaaa = callback + "(" + json.dumps(aaaa, True, False, separators=(',', ':')) + ",%s,%s,%s);" % (z, x, y)
print aaaa

dir = "/var/www/vtile/%s/%s/" % (z, x)
file = "%s.js" % y
Exemplo n.º 6
0
    print "need z"
    exit()
if "x" not in form:
    print "need x"
    exit()
if "y" not in form:
    print "need y"
    exit()
z = int(form["z"].value)
x = int(form["x"].value)
y = int(form["y"].value)
if z > 22:
    exit()
callback = "onKothicDataResponse"

bbox = projections.bbox_by_tile(z + 1, x, y, "EPSG:3857")

style = MapCSS(0, 30)
style.parse(open("styles/osmosnimki-maps.mapcss", "r").read())
zoom = z + 2
aaaa = get_vectors(bbox, zoom, style, "coastline")
aaaa["features"].extend(get_vectors(bbox, zoom, style, "polygon")["features"])
aaaa["features"].extend(get_vectors(bbox, zoom, style, "line")["features"])
aaaa["features"].extend(get_vectors(bbox, zoom, style, "point")["features"])

aaaa = callback + "(" + json.dumps(
    aaaa, True, False, separators=(',', ':')) + ",%s,%s,%s);" % (z, x, y)
print aaaa

dir = "/var/www/vtile/%s/%s/" % (z, x)
file = "%s.js" % y
Exemplo n.º 7
0
    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:
        self.tiles[(z,x,y)]["surface"] = self.tiles[(z,x,y)]["tile"].surface.create_similar(cairo.CONTENT_COLOR_ALPHA, self.tilewidth, self.tileheight)
        self.tiles[(z,x,y)]["thread"] = threading.Thread(None, self.tiles[(z,x,y)]["tile"].update_surface,None, (projections.bbox_by_tile(z,x,y,"EPSG:3857"), z, self.style_backend, lambda p=False: self._callback((z,x,y),p)))
        self.tiles[(z,x,y)]["thread"].start()
        if wait:
          self.tiles[(z,x,y)]["thread"].join()
      return self.tiles[(z,x,y)]["surface"]
  def _callback (self, (z,x,y),last):
    #if last:
    #  print last, "dddddddddddddddddd" 
    if not self._singlethread:
      if ((z,x,y) in self.onscreen or last) and "tile" in self.tiles[(z,x,y)]:
        cr = cairo.Context(self.tiles[(z,x,y)]["surface"])
Exemplo n.º 8
0
            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:
                self.tiles[(z, x, y)]["surface"] = self.tiles[(
                    z, x, y)]["tile"].surface.create_similar(
                        cairo.CONTENT_COLOR_ALPHA, self.tilewidth,
                        self.tileheight)
                self.tiles[(z, x, y)]["thread"] = threading.Thread(
                    None, self.tiles[(z, x, y)]["tile"].update_surface, None,
                    (projections.bbox_by_tile(z, x, y, "EPSG:3857"), z,
                     self.style_backend, lambda p=False: self._callback(
                         (z, x, y), p)))
Exemplo n.º 9
0
z = int(form["z"])
x = int(form["x"])
y = int(form["y"])

import sys
coords = sys.argv[1] #'12/10590/1450'
z, x, y = coords.split('/')
z = int(z)
x = int(x)
y = int(y)
print z, x, y
if z>22:
  exit()
callback = "onKothicDataResponse"

bbox = projections.bbox_by_tile(z+1,x,y,"EPSG:900913")

style = MapCSS(0,30)
style.parse(open("styles/osmosnimki-maps.mapcss","r").read())
zoom = z
aaaa = get_vectors(bbox,zoom,style)
aaaa["features"].extend(get_vectors(bbox,zoom,style,"polygon")["features"])
aaaa["features"].extend(get_vectors(bbox,zoom,style,"line")["features"])
aaaa["features"].extend(get_vectors(bbox,zoom,style,"point")["features"])

aaaa = callback+"("+json.dumps(aaaa,True,False,separators=(',', ':'))+",%s,%s,%s);"%(z,x,y)
#print aaaa

dir = "vtile/%s/%s/"%(z,x)
file = "%s.js"%y