Example #1
0
  def readTile(self, lat0, lon0):
    # We need the tile name to know which row key to get.
    tileName = tileFromLatLon(lat0,lon0)
    print tileName

    # Calculate begin and end position
    begin = posFromLatLon(lat0,lon0)
    end = posFromLatLon(lat0 + 1, lon0 + 1)

    try:
      data = self.cf.get(tileName, column_start=int(begin), column_finish=int(end))
      res = data.values()
    except Exception:
      res = []

    # Now turn the result into a 2D array

    tile = []

    # Calculate tile width (should be 1200, or 10 for test tiles)
    tile_width = int(sqrt(len(res)))
    i = 0
    for x in range(tile_width):
      row = []
      for y in range(tile_width):
        row.append(int(res[i]))
        i = i + 1

      tile.append(row)

    print tile
    return tile
Example #2
0
  def insertTile(self, tile, lat0, lon0):
    # We need the tile name to know which row key to get.
    tileName = tileFromLatLon(lat0, lon0)
    #print "tileName:", tileName

    # Calculate begin position
    begin = posFromLatLon(lat0,lon0)

    # We want to accumulate a bunch of columns before we insert into Cassandra.
    columns = {}
    i=0
    insert_max=25000

    # We drop the top row and right column.
    for row in range(1, len(tile)):
      for col in range(0, len(tile) - 1):
        alt = long(tile[row][col])
        key = long(begin + (row-1) * 1200 + col)
        #print key, alt
        columns[key] = int(alt)

        # We've reached our ceiling, insert. 
        # We could do a bulk insert but since we're hitting one key, a single mutation should be more efficient.
        if i == insert_max:
          self.cf.insert(tileName, columns)
          columns = {}
          i=0

        else:
          i+=1

    # Send insert any thing left after the loop exits.
    self.cf.insert(tileName, columns);
Example #3
0
  def fetchTopLeftAltitude(self, lat, lon):
    tileName = tileFromLatLon(lat,lon)
    pos = posFromLatLon(lat,lon)

    try:
      res = self.cf.get(tileName, columns=[pos])
    except Exception:
      res = []

    return int(res[pos])