Ejemplo n.º 1
0
  //
  // tile methods
  //
  TileEntry tile(String name) {
    String sql =
        format(
            "SELECT a.*, b.is_times_two_zoom"
                + " FROM %s a, %s b"
                + " WHERE a.table_name = ?"
                + " AND a.data_type = ?",
            GEOPACKAGE_CONTENTS, TILE_TABLE_METADATA);

    String[] args = new String[] {name, DataType.Tile.value()};
    log(sql, (Object[]) args);

    Cursor c = db.rawQuery(sql, args);
    try {
      if (c.moveToNext()) {
        TileEntry e = new TileEntry();

        initEntry(e, c);
        e.setTimesTwoZoom(c.getInt(10) == 1);

        sql =
            format(
                "SELECT * FROM %s WHERE t_table_name = ? ORDER BY zoom_level",
                TILE_MATRIX_METADATA);
        args = new String[] {name};

        log(sql, (Object[]) args);

        Cursor d = db.rawQuery(sql, args);
        try {
          TilePyramidBuilder tpb = TilePyramid.build();
          if (d.moveToNext()) {
            tpb.tileSize(d.getInt(4), d.getInt(5));

            do {
              tpb.grid(d.getInt(1), d.getInt(2), d.getInt(3));
            } while (d.moveToNext());
          }

          e.setTilePyramid(tpb.pyramid());
        } finally {
          d.close();
        }
        return e;
      }
    } finally {
      c.close();
    }

    return null;
  }
Ejemplo n.º 2
0
  TileCursor cursor(TileEntry entry, Long z1, Long z2, Long x1, Long x2, Long y1, Long y2) {

    final List<String> q = new ArrayList<String>();
    if (z1 != null && z1 > -1) {
      q.add("zoom_level >= " + z1);
    }
    if (z2 != null && z2 > -1) {
      q.add("zoom_level <= " + z2);
    }
    if (x1 != null && x1 > -1) {
      q.add("tile_column >= " + x1);
    }
    if (x2 != null && x2 > -1) {
      q.add("tile_column <= " + x2);
    }
    if (y1 != null && y1 > -1) {
      q.add("tile_row >= " + y1);
    }
    if (y2 != null && y2 > -1) {
      q.add("tile_row <= " + y2);
    }

    StringBuilder where = new StringBuilder();
    if (!q.isEmpty()) {
      for (String s : q) {
        where.append(s).append(" AND ");
      }
      where.setLength(where.length() - 5);
    }

    // TODO: sort
    Cursor c =
        db.query(
            entry.getTableName(),
            new String[] {"zoom_level", "tile_column", "tile_row", "tile_data"},
            where.toString(),
            null,
            null,
            null,
            null);
    return new TileCursor(c);
  }